Using the IsTrue Operator

time to read 9 min | 1734 words

Matthijs was kind enough to answer the question I asked about the IsTrue operator. It is usable from C#, here is my new base object:

class Program

{

    static void Main (string[] args)

    {

        IsNull(new AyendeObject());

        IsNull(null);

           

    }

 

    private static void IsNull(AyendeObject w)

    {

        if (w)

            Console.WriteLine("Not Null");

        else

            Console.WriteLine("Null");

    }

}

 

public class AyendeObject

{

    public static bool operator true(AyendeObject b)

    {

        return b != null;

    }

 

    public static bool operator false(AyendeObject b)

    {

        return b == null;

    }

}

Can you think which language bias I'm showing here? Can you imagine the kind of stuff you can have if Linq will allow extention operators?