I would like to declare common handler for variety of events, that will basically route events to the JavaScript part of the app. I myself come for JS/AS3 background, where something like this is a relatively simple thing to do. SilverLight and C# look quite stricter though.
The plan is like follows, JS will call a special [ScriptableMember] with a class name to instantiate and method to call, as string arguments. [ScriptableMember] then must contruct an instance of the class and optionally subscribe to the events, that can be fired by that instance. Events to subscribe to, will be exposed in public static struct of some kind. [ScriptableMember] will have to extract event properties from that struct and subscribe with the single event handler to all of them. Common single event handler then should translate C# events to JS ones.
Obviously everything should be generalized and automated in some kind of factory logic.
One big problem to this is that I cannot know beforehand what will be the type of delegate or EventArgs object. And even if I knew it would have been troublesome to create an overload for each and every case. Is there anyway to define a generic event handler in C#?
Answer: 1
Every event args must be inherited from EventArgs class. If you follow this rule, you just can declare your handler like
public void GenericHandler(object sender, EventArgs e) and subscribe it to any event
Answer by dvvrd for Is there anyway to define a single event handler for variety of events in C#?
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog