Get Index Parameters : PropertyInfo « Reflection « VB.Net






Get Index Parameters

 
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"}
    Public Default Property Item(ByVal Index As Integer) As String
        Get
            Return strings(Index)
        End Get
        Set
            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()

        pi = t.GetProperty("Item")
        params = pi.GetIndexParameters()
        Console.WriteLine(t.FullName & "." & pi.Name & " has " & params.GetLength(0) & " parameters.")
        For Each p As ParameterInfo In params
            Console.WriteLine("   Parameter: " & p.Name)
        Next

        Return 0
    End Function
End Class

   
  








Related examples in the same category

1.PropertyInfo.Attributes Property gets the attributes for this property.
2.PropertyInfo.CanRead
3.PropertyInfo.CanWrite
4.PropertyInfo.GetAccessors
5.PropertyInfo.GetGetMethod returns the public or non-public get accessor for this property.
6.Get and display the GetGetMethod Method for each property
7.Display the GetGetMethod without using the MethodInfo
8.PropertyInfo.GetIndexParameters
9.PropertyInfo.GetSetMethod
10.Display the GetSetMethod without using the MethodInfo
11.PropertyInfo.MemberType
12.PropertyInfo.PropertyType Property
13.PropertyInfo.SetValue
14.LocalVariableInfo Class (System.Reflection)_VB.htm