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.
精彩评论