Skip to main content

Add Extension Methods(Like C# 3.0) to keep version compatible !!!

No replies
Joined: 2008-03-06

In C# 3.0, microsoft add Extension Methods (????), maybe microsoft want to use it complete LNQ, BUT I find a way to keep version compatible.
e.q. There is a class SomeClass in jdk1.5, and I call both MethodA and MethodB in some application run on jre1.5+, everything is ok. Someday, my customer told me that the application has to support jdk1.4, then I think it's an nightmare now ! BUT if there is Extension Methods, the problem is very simple, I just add a class to provide an static method, and life is so good.

class SomeClass //from jdk1.3
public int MethodA() {} //from jdk 1.4
public int MethodB() {} //from jdk 1.5

public static class SomeClassExtensions
public int MethodB(this SomeClass someClassObi) {} //from jdk 1.5

Extension Methods is the good way to keep version compatible, maybe it can not work for all case, BUT i think it's the most simple and security way--- Only compiler do something, and can be used on all jdk version.