Extension methods and Curried 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

Comments (8)

  1. You’ve been kicked (a good thing) – Trackback from DotNetKicks.com

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

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

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

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

  6. Ultracet. says:

    Ultracet. Is ultracet addictive. Ultracet addiction.

  7. Srinu Tamada says:

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

  8. Mariaaa says:

    I suffer from Fibromyalgia. Although prescribed 8 tablets daily, I typically take 4 if I can get away with it. It's very effective for pain.


Skip to main content