Ticket #331 (assigned enhancement)

Opened 6 years ago

Last modified 5 years ago

Bind to C# extension methods

Reported by: Charles Owned by: hopscc
Priority: major Milestone:
Component: Cobra Compiler Version: 0.9.4
Keywords: extension methods Cc:


Cobra has its own extension methods feature supported back in .NET 2.0. C# added these for .NET 3.0 (or 3.5, I forget) and uses a different declaration technique.

Cobra should be enhanced to bind method calls to C# extension methods. There are numerous .NET libraries that use these.

I don't think any of the other tickets about extension methods cover this.

Here is a test case:

@ref 'System.Core'

use System.Linq

class P

    def main
        list = [1, 2, 3, 4, 5, 6]
        assert list.elementAt(3) == 4
        assert = x * 2) == [2, 4, 6, 8, 10, 12]
        assert list.sum == 21

Change History

Changed 5 years ago by hopscc

  • owner set to hopscc
  • status changed from new to assigned

Looking at this now ...

Assembly scan by cobra needs to detect Extension methods (marked with ExtensionAttribute) and generate a cobra Extension Node for them - currently only recognises its own extension methods ( made in cobra) but not pure C# made ones...

Also need fix cobras codegen for its extension methods so that non cobra programs
(C#) can pickup extension methods made in cobra. (just needs the right C# isnames and keywords).

Linq uses this and Generics so there will probably be additional dancing for that..

Changed 5 years ago by nerdzero

After this is done can Ticket #1 be closed?

Changed 5 years ago by hopscc

Yeah presumably.

This is coming along - recognising and generating cobra extensions from suitably tagged entries in .Net Library DLLs.

One wrinkle is that .Net allows extensions of Enums and cobra doesnt - unfortunately
such is used in Hibernate.dll..
FTM I'm just going to ignore these from a .Net dll

Changed 5 years ago by Charles

Maybe we need a ticket for the enums.

Note: See TracTickets for help on using tickets.