考虑以下情况:
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?
答案 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);