How to get the actual property name when referencing an interface?
Consider the following case:
Public Interface IHasDateUpdated
Property DateUpdated As DateTime
End Interface
Public Class MyClass
Implements IHasDateUpdated
Public Property MyDateUpdated As DateTime Implements IHasDateUpdated.DateUpdated
End Class
Now, assuming I was referencing an instance of MyClass
as an IHasDateUpdated
; how would I determine the actual name of t开发者_开发问答he property that implements the interface property via reflection?
For example:
Dim x As IHasDateUpdated = New MyClass()
' How do I derive "MyDateUpdated" from "x" using x.DateUpdated?
Sorry flor the c# answer but you should be able to translate this I'm 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);
精彩评论