Global Methods in C# 3.0
As you probably know, you can't define a stand alone method in C#, It must always reside within a class. C# 3.0 adds extention methods to the lagnague, which allows you to add methods to existing classes.
We can take advantage of that to implement a "global" method, like this:
        public static class GlobalMethods
        {
           public static bool IsNull(this object ignored, object obj)
           {
               return obj != null;
           }
        }    
Now I can use this like this:
This is not really useful for this case, but it is a very big step for fluent interfaces. At the moment having to have a class name prefix is somewhat of an issue with fluent interfaces. Which sometimes doesn't make sense in the sentence structure we are trying to create.
 

Comments
Comment preview