Mega Code Archive

 
Categories / VB.Net / Reflection
 

PropertyInfo GetIndexParameters

Imports System Imports System.Reflection Imports System.Collections Imports Microsoft.VisualBasic Public Class MyProperty     Private myCaption As String = "A Default caption"     Public Property Caption() As String         Get             Return myCaption         End Get         Set(ByVal Value As String)             If myCaption <> value Then                 myCaption = value             End If         End Set     End Property     Private strings() As String = {"abc", "def", "ghi", "jkl"}     Default Public Property Item(ByVal Index As Integer) As String         Get             Return strings(Index)         End Get         Set(ByVal value As String)             strings(Index) = Value         End Set     End Property End Class Public Class Example     Public Shared Function Main() As Integer         Dim t As Type = GetType(MyProperty)         Dim pi As PropertyInfo = t.GetProperty("Caption")         Dim params As ParameterInfo() = pi.GetIndexParameters()         Console.WriteLine(pi.Name & " has " & params.GetLength(0) & " parameters.")         Return 0     End Function End Class