开发者

How to parse a delegate method from a xml file?

I would like to be able to have a button for my interface that uses different delegates if pressed etc.

And in order to make it easy it would be 开发者_StackOverflownice to be able to load the buttons from XML. I already have it setup like this:

<EclipseButton name="button1" texkey="thumbnail" istodraw="True">
 <position>
  <x>10</x>
  <y>10</y>
 </position>
 <width>64</width>
 <height>64</height>
</EclipseButton>

But I would like to be able to add:

<IfPressed>
 <![CDATA[
 Console.WriteLine("The button is pressed");
 ]]>
</IfPressed>

And then I can convert the text in cdata as if it were a lambda:

() => { Console.WriteLine("The button is pressed"); }

Is there anyway to make this possible?


As an alternate to @Yahia's response, you can create a list of pre-defined actions (similar to what the ASP AJAX Control Toolkits do for actions) and allow the markup to specify order, etc. e.g.

<IfPressed>
  <WriteToConsole Text="The button is pressed" />
</IfPressed>

Then parse the collection as a to-do list, going through each added item and executing it.


it is possible although not easy - see http://msdn.microsoft.com/de-de/library/650ax5cx.aspx

You would need to compile the code at runtime and use reflection to invoke etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜