Welcome to MSDN Blogs Sign in | Join | Help

Extension methods and Curried Delegates

Delegates 

Since Extension methods behave like instance method it makes sense that we should be able to create delegates that would accept the instance method signature, to this end we have included Adding an Extension Methods to delegate invocation List   

Extension methods can now be used like an instance methods when being added to a delegate invocation list. So for Extension method Bar defined as    

static int Bar(this foo f)

{

    return f.val;

}

 

We will now allow delegates that accept the instance method signature to be able to add Extension methods to their invocation list. So for,

delegate int d1();

We can now do

d1 d = f.Bar;

In order to do these the generated IL will look like so   

IL_0000:  nop

IL_0001:  newobj     instance void Test.foo::.ctor()

IL_0006:  stloc.0

IL_0007:  ldloc.0

IL_0008:  ldftn      int32 Test.Extension::Bar(class Test.foo)

IL_000e:  newobj     instance void Test.d1::.ctor(object,   native int)

 

Where Test.d1 is the delegate class that we generate. That is I am treating the static method as an instance method and the instance variable is curried to the delegate.   

Only Extension methods on reference types are supported for this feature. So you can pass a value type as the instance argument to the extension methods, but as long as its boxed.

I encourage users to try this feature in Beta1 released a few weeks back, and give feedback ...  

kick it on DotNetKicks.com
Published Tuesday, May 01, 2007 4:19 PM by Sree_c

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Extension methods and Curried Delegates

Tuesday, May 08, 2007 4:27 PM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# Community Convergence XXVII

Monday, May 14, 2007 2:14 AM by Charlie Calvert's Community Blog

Welcome to the 27th Community Convergence. I use this column to keep you informed of events in the C#

# Debugging Features in C# 3.0 Part 1

Tuesday, May 29, 2007 7:55 PM by Sree's ventures in code space

Overview C# 3.0 introduces many new constructs and opens entirely new ways of thinking and developing

# More on extension methods

Thursday, February 28, 2008 2:37 AM by Willem Meints

Sree wrote down some more details on extension methods. The standard functionality is quite easy to use,

# Celexa.

Friday, July 11, 2008 5:00 PM by Celexa and decreased sex drive.

Celexa lexapro dose. Heavy drinking celexa. Celexa. Common withdrawal effects of celexa. Celexa side effects.

# Ultracet.

Friday, July 18, 2008 5:40 PM by Ultracet.

Ultracet. Is ultracet addictive. Ultracet addiction.

# re: Extension methods and Curried Delegates

Thursday, April 09, 2009 7:41 AM by Srinu Tamada

I am not able to understand what are you trying to tell. Can you elaborate little bit?

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker