Link to home
Start Free TrialLog in
Avatar of dougschultz
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.
ASKER CERTIFIED SOLUTION
Avatar of Yttribium
Yttribium

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dougschultz
dougschultz

ASKER

I will be more clear about what I need.  In use of Microsoft's Composite UI Application Block, commands are often used to communicate Toolbar button clicks to the handler within the module.  To accomplish this, it is necessary for the module to create the command and to tell CAB that a particular method should handle the invokation of the command.  This would done something like the following:

[CommandHandler("CommandName")]
public void toolbarButton_Click(object sender, EventArgs e)
{
            //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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.