This project is read-only.

converting to and from nullable types

Feb 23, 2010 at 7:48 AM

hi,

am slowly getting to grips with glue, and have a quick question regarding mapping to and from nullable types. say i have:

         decimalConverter = new Glue.Converters.QuickConverter<decimal, decimal?>
                (t1 => t1 == 0M ? null : (decimal?)(t1), t2 => t2.HasValue ? t2.Value : 0M);

going from decimal a to decimal? a works fine. however going from decimal? a to decimal a throws an exception if it's null

 

many thanks,

Feb 23, 2010 at 7:22 PM

 

Thanks for the question.
There has been an issue when passing null as fromvalue. This issue was fixed in changeset 34745. It is not yet a part of an official release. I will make a new release soon. In the meantime, you can get the latest source and compile it yourself.
I have written a unit test for your question. does it answer your question?

GlueTests.BaseConverterTests.When_mapping_between_null

 

Thanks for the question.

 

There has been an issue with passing null as fromvalue. This issue was fixed in changeset 34745. It is not yet a part of an official release. I will make a new release soon. In the meantime you can get the latest source. 

I have written a unit test for your question. 

GlueTests.BaseConverterTests.When_mapping_between_nulls:

 

 

[Fact]
public void Should_return_value_when_nullable_type_is_null()
{
    var decimalConverter = new QuickConverter<decimal, decimal?>
       (t1 => t1 == 0M ? null : (decimal?)(t1), t2 => t2.HasValue ? t2.Value : 0M);
    Assert.Equal(0, decimalConverter.MapTowardsLeft(null)); 
}

 

Does that answer your question?

.Tore

 

 

 

 

Feb 26, 2010 at 9:28 PM

hi tore,

 

that's great. thanks. i'll give it a whirl. also, is it possible to map object hierachies?

 

mike

Feb 27, 2010 at 7:00 AM
Edited Feb 27, 2010 at 7:01 AM

Sure,

Here's how to map object hierarchies:

http://glue.codeplex.com/wikipage?title=Nested%20mapping%20and%20Flattening&referringTitle=Home

.Tore

Feb 27, 2010 at 5:10 PM

ah yes, that looks like it. thanks