J
Jason Bell
Give the following custom attribute:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class WidgetEventAttribute : System.Attribute
{
protected Cegui.EventHandler mEventHandler = null;
public WidgetEventAttribute( string widgetname, string
eventname )
{
mEventHandler = new Cegui.EventHandler();
mEventHandler.Subscribe(
WindowManager.Instance.getWindow(widgetname), eventname );
}
public WidgetEventAttribute( Cegui.Window window, string
eventname )
{
mEventHandler = new Cegui.EventHandler();
mEventHandler.Subscribe( window, eventname );
}
}
That's used in the following way:
[WidgetEvent(this, Cegui.PushButton.EventClicked)]
protected bool HandleClicked()
{
Console.WriteLine("Oh ye of little faith!");
return true;
}
How would I know what method the particular attribute is assigned to?
WidgetEventAttribute is intended to create a delegate to the function
it's assigned to, and marshal that delegate as a function pointer to an
unmanaged library for a callback.
I've seen lots of examples where one reflects to find all methods, then
gets a list of attributes assigned to it. I'd like to do the opposite:
from within the a particular instance of WidgetEventAttribute, find what
method it's assigned to.
Before anyone asks, I have my reasons for doing it this way, largely due
to the weird way this library handles events.
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class WidgetEventAttribute : System.Attribute
{
protected Cegui.EventHandler mEventHandler = null;
public WidgetEventAttribute( string widgetname, string
eventname )
{
mEventHandler = new Cegui.EventHandler();
mEventHandler.Subscribe(
WindowManager.Instance.getWindow(widgetname), eventname );
}
public WidgetEventAttribute( Cegui.Window window, string
eventname )
{
mEventHandler = new Cegui.EventHandler();
mEventHandler.Subscribe( window, eventname );
}
}
That's used in the following way:
[WidgetEvent(this, Cegui.PushButton.EventClicked)]
protected bool HandleClicked()
{
Console.WriteLine("Oh ye of little faith!");
return true;
}
How would I know what method the particular attribute is assigned to?
WidgetEventAttribute is intended to create a delegate to the function
it's assigned to, and marshal that delegate as a function pointer to an
unmanaged library for a callback.
I've seen lots of examples where one reflects to find all methods, then
gets a list of attributes assigned to it. I'd like to do the opposite:
from within the a particular instance of WidgetEventAttribute, find what
method it's assigned to.
Before anyone asks, I have my reasons for doing it this way, largely due
to the weird way this library handles events.