22

Jan

TNX ResolveIT

 

 

ResolveIT is a simple Extension Method, requiring .NET >= 4 or SL >= 4 or WP >= 7 or RT

It allow you skipping the NullReferenceException in a multi dot-notation form like in this test:

 

[TestMethod, ExpectedException(typeof(NullReferenceException))]
public void UsualUsageTest()
{
    var example = new ExampleClass();

    //i need the example.NullableVale.Length
    //because it's a reference type, usually we'll have a NullReferenceException

    var Length = example.NullableValue.Length;
}

[TestMethod]
public void ResolveITUsageTest()
{
    var example = new ExampleClass();

    //i need the example.NullableVale.Length
    //using resolveIT we'll skip the null value for NullabelValue property,
    //instead, we'll have the default value of Length (the last expression)

    var Length = example.NullableValue.Resolve(x => x.Length);
    Assert.AreEqual(Length, 0);
}

Take (or find) it on Nuget: https://www.nuget.org/packages/TnxResolveIT/

by Antonio Esposito on 1/22/2014
Post archive