4

Possible Duplicate:
Can attributes be added dynamically in C#?

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

For example: Can I decorate 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!

Community
  • 1
  • 1
Andrew Florko
  • 7,672
  • 10
  • 60
  • 107

1 Answers1

1

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.

Anton Gogolev
  • 113,561
  • 39
  • 200
  • 288