Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何以编程方式分配.Net属性?_C#_.net_Reflection - Fatal编程技术网

C# 如何以编程方式分配.Net属性?

C# 如何以编程方式分配.Net属性?,c#,.net,reflection,C#,.net,Reflection,可能重复: 是否可以通过编程方式将.net属性分配给类/方法 例如: 我可以用取自外部文件的Guid/ProgId属性装饰我的自定义.net com类吗?比如: typeof(MyComObject).AssignAttribute(new GuidAttribute("...")); 而不是像这样的硬代码: [Guid("...")] class MyComObject { } 提前谢谢你 视情况而定ICustomTypeDescriptor允许对类的几乎每个部分(可能根本不存在)执行任

可能重复:

是否可以通过编程方式将.net属性分配给类/方法

例如: 我可以用取自外部文件的Guid/ProgId属性装饰我的自定义.net com类吗?比如:

typeof(MyComObject).AssignAttribute(new GuidAttribute("..."));
而不是像这样的硬代码:

[Guid("...")]
class MyComObject
{
}

提前谢谢你

视情况而定
ICustomTypeDescriptor
允许对类的几乎每个部分(可能根本不存在)执行任何您想要的操作,但无论您试图将对象提供给哪个系统,都可能不会使用此特定接口
PropertyGrid
广泛使用此接口。

仅当您在运行时创建类本身时。