Anonymous event class

Source: Internet
Author: User

I found some pretty funny things when I was on the anonymous Commission a while ago.

If I go through and execute a list<delegate> then I am free to control whether I want to perform the steps I need

For example, list{a,b,c,d,e},a~e say whether to go to an attraction in the park,

So I was very poor at these events, and then I came to the guest a, and he just told me the few sights he wanted to go to.

I can arrange a route for him (for example: execution order Cdabe) It's convenient to cancel temporarily or to add a spot or something.

So, in order to keep the list in almost any form of method, I chose to use func<object[], object>

But this will create a problem, that is, when I join the list of the delegate hypothesis is not func<object[], object> what to do?

So I chose to use delegate to represent all forms of delegation, so I set up a func<> shell

So I can throw any form delegate into the func<>, and both the return value and the value can be accepted.

So that's what happens.

This is a list

public static list<func<object[], delegate>> delegatelist = new list<func<object[], delegate>>

{

This is the first element in the list, and this is an anonymous delegate, formally func<object[], delegate>

Useless, the form is func<object[], delegate> object[], but no use, I have not found a reason to add this

(useless) =
{

This is an anonymous delegate, formally delegate, here is an example of func<object[],object>, and not limited to this

func<object[],object> function = (OBJS) = =
{

Here is the return value, formally the object in the func<object[],object>.
return new object ();
};

Here is the return value, formally Func<in T, out tresult> in the out TResult this part
return function;
},

This is the second element in the list.

This is an anonymous delegate.

(useless) =>{func<object[],object> function = (OBJS) =>{return new Object ();};},

This is the third element in the list.

This is a acion commission.

(useless) =>{action<object[]> function = (OBJS) =>{};},
};

 Public classMoeevent {
Add a new method, this is inserted, the list will be one more element Public voidAddevent (func<Object[],Object>function) { if(function.) GetType () = =typeof(func<Object[],Object>) ) {Func<Object[], delegate> f = (useless) + = {returnfunction;}; MOESCRIPT.DELEGATELIST.ADD (f); } }
The function method is merged into the front of an event, this is a multicast, the list does not have an extra element Public voidAddprefixtoevent (intIndex, func<Object[],Object>function) { if(Index < MoeScript.delegateList.Count && index >=0) { if(function.) GetType () = =typeof(func<Object[],Object>) && Moescript.delegatelist[index]. GetType () = =typeof(func<Object[], delegate>) ) {Func<Object[],Object> OLDFC = (func<Object[],Object>) Moescript.delegatelist[index] (New Object[] { }); Func<Object[], delegate> FC = (useless) ={Func<Object[],Object> NEWFC = function +oldfc;//the difference herereturnNEWFC; }; Moescript.delegatelist[index]=FC; } } }
The function method is merged into the back of an event, this is a multicast, the list does not have an extra element Public voidAddsuffixtoevent (intIndex, func<Object[],Object>function) { if(Index < MoeScript.delegateList.Count && index >=0) { if(function.) GetType () = =typeof(func<Object[],Object>) && Moescript.delegatelist[index]. GetType () = =typeof(func<Object[], delegate>) ) {Func<Object[],Object> OLDFC = (func<Object[],Object>) Moescript.delegatelist[index] (New Object[] { }); Func<Object[], delegate> FC = (useless) ={Func<Object[],Object> NEWFC = OLDFC +function;//the difference herereturnNEWFC; }; Moescript.delegatelist[index]=FC; } } } }

Anonymous event class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.