dougschultz
asked on
Add attributes to methods at runtime? (C#, .NET 2.0 Reflection)
What I am hoping for is a way to accept a method pointer as a parameter in a subroutine (no problem there) and then apply attributes to that method. I am building a CAB-based (Microsoft Composite UI Application Block) application and want to encapsulate some of the functionality that the module developer will need. This is a C# project in .NET 2.0. For those familiar with CAB, I want to encapsulate the addition of a toolbar item, including creating a Command decorating the clickHandler with the CommandHandler attribute.
I am able to get the Attributes property from the method using reflection, but this doesnt have any option for Add. I don't know if what I am trying to do is even possible. I need some help. Thanks.
I am able to get the Attributes property from the method using reflection, but this doesnt have any option for Add. I don't know if what I am trying to do is even possible. I need some help. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys, but it doesnt appear that this is possible, at least not without doing some crazy stuff like building a class at runtime, which will not meet my needs anyway.
ASKER
[CommandHandler("CommandNa
public void toolbarButton_Click(object
{
//TODO: Handle button click
}
What I hope to do is encapsulate the creation of the command and the tagging of this method. This way, the module developer would not need to know about the commands at all. What I would do then is provide some method which will take information about the toolbar button, as well as a reference to the above handler method. I could then apply the CommandHandler attribute to that method.
Any clues?