Forums

Extend generic types

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Extend generic types

Postby Charles » Tue Dec 30, 2008 2:22 am

I have implemented generic type extensions. That is, you can now "extend" on a generic type such as IList<of T>.

Quick example:
extend Dictionary<of TKey, TValue>

def lastValue as TValue
keys = List<of TKey>(.keys)
keys.sort
return this[keys[keys.count-1]]


class P

def main is shared

d = {
'a': 1,
'b': 2,
'z': 3,
'c': 4,
'd': 5,
}

assert d.lastValue == 3


You can browse the test cases in your local workspace or online at http://cobra-language.com/trac/cobra/browser/cobra/trunk/Tests/420-extensions/400-extend-generics.

This feature will enable us to add convenience methods to IList, IDictionary, etc.

If you find any problems, please report them here.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Extend generic types

Postby gauthier » Tue Dec 30, 2008 11:43 am

that's looking handy :)

as for .net extension methods, do you plan to support C# 3 extension method call and definition soon?

def transform(this text as String) as String is shared
return text + text
gauthier
 
Posts: 116

Re: Extend generic types

Postby Charles » Tue Dec 30, 2008 9:15 pm

If you mean syntaxwise, no. The Cobra syntax is already established as:
extend String
def transform as String
return this + this

If you mean translating Cobra's extensions down to the C# syntax so that C# 3 programs see them properly, yes we would do that as part of supporting .NET 3.5+. Same with reading C#/VB extensions from .DLLs.

But right now Cobra is still on .NET 2.0 and I haven't given much thought to moving to later versions of .NET.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 80 guests