How can a property resolve its own name and type with reflection?

Posted by Tim Santeford on Stack Overflow See other posts from Stack Overflow or by Tim Santeford
Published on 2010-03-12T18:38:52Z Indexed on 2010/03/12 18:57 UTC
Read the original article Hit count: 159

Filed under:
|
|

Is there a way for a property to access its own name and type at runtime using reflection? I want to access this info without hard coding the name or index of the property in the class.

Simple Example Code:

Private ReadOnly Property MyProperyName() As String
    Get
        Console.WriteLine((Get Current Property Info).Type.ToString)
        Console.WriteLine((Get Current Property Info).Name)
        Return ""
    End Get
End Property

Expected output:

System.String
MyPropertyName

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about reflection