开发者

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

开发者 https://www.devze.com 2023-04-13 06:27 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Can attributes be added dynamically in C#?
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

精彩评论

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

关注公众号