开发者

How do I assign .Net attributes programmatically? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Can attributes be added dynamically in C#?

Is it possible to assign .net Attribute to class/method programmatically?

For example: Can I 开发者_如何学Pythondecorate my custom .net com classes with Guid/ProgId attributes taken from external file? Something like:

typeof(MyComObject).AssignAttribute(new GuidAttribute("..."));

instead of hardcode like:

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

Thank you in advance!


It depends. ICustomTypeDescriptor allows to almost anything you want to almost every part of a class (which might not even exist for that matter), but this particular interface might not be used by whatever system you're trying to feed your object to. PropertyGrid uses this interface extensively, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜