更具体地说,如果我有:
public class TempClass : TempInterface { int TempInterface.TempProperty { get; set; } int TempInterface.TempProperty2 { get; set; } public int TempProperty { get; set; } } public interface TempInterface { int TempProperty { get; set; } int TempProperty2 { get; set; } }
如何使用反射来获取显式实现TempInterface的属性的所有propertyInfos?
谢谢.
我认为您正在寻找的类是System.Reflection.InterfaceMapping.
Type ifaceType = typeof(TempInterface); Type tempType = typeof(TempClass); InterfaceMapping map = tempType.GetInterfaceMap(ifaceType); for (int i = 0; i < map.InterfaceMethods.Length; i++) { MethodInfo ifaceMethod = map.InterfaceMethods[i]; MethodInfo targetMethod = map.TargetMethods[i]; Debug.WriteLine(String.Format("{0} maps to {1}", ifaceMethod, targetMethod)); }