Hello Michael,
>Is this even possible or am I just lost on syntax?
I made some tests with the following implementation:
class Program {
static void Main(string[] args) {
Console.WriteLine("Hi".AddSomething(" there"));
Console.WriteLine(Helper.AddSomethingLambda("Hi", " there"));
Console.ReadLine();
}
public static class Helper {
public static string AddSomething(this string val, string addOn) {
return val + addOn;
}
public static Func<string,string,stringAddSomethingLambda =
(val,addOn) =val + addOn;
}
}
I don't find a way to use the "this" keyword in the "AddSomethingLambda"
declaration that the compiler likes. Seems to me this doesn't work... it's
probably rather logical - extension methods work, afaik, because the
compiler converts the call into the "standard" syntax of a call to
Helper.XXX at compile time. While my example doesn't show this, it would
theoretically be possible that my AddSomethingLambda didn't even contain
anything - it's a runtime assignment, not something that can be evaluated
at compile time.
Oliver Sturm
--
http://www.sturmnet.org/blog