111,119
社区成员
发帖
与我相关
我的任务
分享 [System.Runtime.InteropServices.Guid("ok")]
class My
{
}namespace Myself
{
[AttributeUsage(AttributeTargets.Delegate | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Assembly, Inherited = false), ComVisible(true)]
public sealed class GuidAttribute : Attribute
{
// Fields
internal string _val;
// Methods
public GuidAttribute(string guid)
{
this._val = guid;
}
// Properties
public string Value
{
get
{
return this._val;
}
}
}
}
[Myself.Guid("OK")]
class You
{
}
[ComVisible(true)]
[Guid("00000000-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface Interface1
{
int hello();
}


属性是序列化后存储在程序集中的.你使用[Guid("ok")]给一个类添加属性的时候,编译器会调用GuidAttribute类的构造函数,而GuidAttribute会试着用你传入的参数去构造一个Guid."ok"不是一个合法
LZ你很有才...头一次见到这种GUID.建议你先去了解下什么叫Guid.