代码之家  ›  专栏  ›  技术社区  ›  DanP

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

  •  0
  • DanP  · 技术社区  · 14 年前

    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 回复  |  直到 14 年前
        1
  •  1
  •   Kell    14 年前

    对不起,弗洛尔,我的答案是,但你应该能翻译这个,我是苏尔:)

    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);