如何在引用接口时获取实际的属性名称?

时间:2010-10-29 11:33:33

标签: vb.net reflection

考虑以下情况:

Public Interface IHasDateUpdated
     Property DateUpdated As DateTime
End Interface

Public Class MyClass
     Implements IHasDateUpdated

     Public Property MyDateUpdated As DateTime Implements IHasDateUpdated.DateUpdated
End Class

现在,假设我将MyClass的实例引用为IHasDateUpdated;我如何通过反射确定实现接口属性的属性的实际名称?

例如:

Dim x As IHasDateUpdated = New MyClass()
' How do I derive "MyDateUpdated" from "x" using x.DateUpdated?

1 个答案:

答案 0 :(得分:1)

对不起,欢迎来到c#的答案,但你应该能够翻译这个我是suer:)

InterfaceMapping im = y.GetInterfaceMap(typeof(IHasDateUpdated ));
        foreach (MethodInfo info in im.TargetMethods)
        {
            if (info.IsPrivate)
                MessageBox.Show(info.Name + " is private");
        }
        MessageBox.Show(y.FullName);