在查看Object类的定义时发现Object使用了ClassInterface,而且是ClassInterfaceType.AutoDual故查看一下具体什么,原来是类接口是为互操作而设计的,其中写到托管代码中基类或接口的中顺序也会影响互操作,真是不应乱该动代码。:)

 

类接口是未在托管代码中显式定义的接口,它将公开在 .NET 对象上显式公开的所有公共方法、属性、字段和事件。例如,对于 Mammal 类,类接口为 _Mammal。

例如,如果 Mammal 类扩展 MammalSuperclass 类,而 MammalSuperclass 本身又扩展 System.Object,.NET 对象将向 COM 客户端公开三个名为 _Mammal、_MammalSuperclass 和 _Object 的接口。

http://msdn.microsoft.com/zh-cn/library/4fcadw4a.aspx

ClassInterfaceAttribute 类:http://msdn.microsoft.com/zh-cn/library/system.runtime.interopservices.classinterfaceattribute.aspx

 

其中写到:

限制将双绑定接口选项用于类接口。

在其他所有情况下,应避免将类接口设置为双绑定。

这样的说明会促使后期绑定的客户端在运行时缓存 DispId。

 

看来Object中public的方法非static的顺序应该是不会更改的了。

 

[Serializable, ClassInterface(ClassInterfaceType.AutoDual), ComVisible(true)]
public class Object
{
    // Methods
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public Object();
    [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
    public virtual bool Equals(object obj);
    [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
    public static bool Equals(object objA, object objB);
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    protected virtual void Finalize();
    [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
    public virtual int GetHashCode();
    [MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
    public extern Type GetType();
    [MethodImpl(MethodImplOptions.InternalCall), SecuritySafeCritical]
    protected extern object MemberwiseClone();
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
    public static bool ReferenceEquals(object objA, object objB);
    public virtual string ToString();
}

 

相关文章: