Skip to content

Commit

Permalink
fix issue #56
Browse files Browse the repository at this point in the history
  • Loading branch information
esskar committed Aug 27, 2015
1 parent 05c8dfc commit 58de914
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
60 changes: 60 additions & 0 deletions src/Serialize.Linq.Tests/Issues/Issue56.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Serialize.Linq.Serializers;

namespace Serialize.Linq.Tests.Issues
{
[TestClass]
public class Issue56
{
[TestMethod]
public void SerializeContainsWithNullablesAndWithoutNullableKey()
{
var enterpriseKeys = new List<long?> {1, 2, 3, 4};

var predicatePart =
(Expression<Func<GroupEntityWithoutNullable, bool>>)
(groupType =>
enterpriseKeys.Contains(groupType.GroupEnterpriseKey));

var serializeTo = new ExpressionSerializer(new XmlSerializer())
{
AutoAddKnownTypesAsListTypes = true
};
var predicatePartSerializedToString = serializeTo.SerializeText(predicatePart);

Assert.IsNotNull(predicatePartSerializedToString);
}

[TestMethod]
public void SerializeContainsWithNullablesAndWithNullableKey()
{
var enterpriseKeys = new List<long?> { 1, 2, 3, 4 };

var predicatePart =
(Expression<Func<GroupEntityWithNullable, bool>>)
(groupType =>
enterpriseKeys.Contains(groupType.GroupEnterpriseKey));

var serializeTo = new ExpressionSerializer(new XmlSerializer())
{
AutoAddKnownTypesAsListTypes = true
};
var predicatePartSerializedToString = serializeTo.SerializeText(predicatePart);

Assert.IsNotNull(predicatePartSerializedToString);
}

class GroupEntityWithoutNullable
{
public long GroupEnterpriseKey { get; set; }
}

class GroupEntityWithNullable
{
public long? GroupEnterpriseKey { get; set; }
}
}
}
1 change: 1 addition & 0 deletions src/Serialize.Linq.Tests/Serialize.Linq.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<Compile Include="Issues\Issue41.cs" />
<Compile Include="Issues\Issue43.cs" />
<Compile Include="Issues\Issue50.cs" />
<Compile Include="Issues\Issue56.cs" />
<Compile Include="MemberInfoExtensionsTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
12 changes: 10 additions & 2 deletions src/Serialize.Linq/Serializers/SerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,16 @@ private IEnumerable<Type> ExplodeKnownTypes(IEnumerable<Type> types)
yield return type.MakeArrayType();
else if (this.AutoAddKnownTypesAsListTypes)
yield return typeof(List<>).MakeGenericType(type);
if (!type.IsClass)
yield return typeof(Nullable<>).MakeGenericType(type);

if (type.IsClass)
continue;

var nullableType = typeof (Nullable<>).MakeGenericType(type);
yield return nullableType;
if (this.AutoAddKnownTypesAsArrayTypes)
yield return nullableType.MakeArrayType();
else if (this.AutoAddKnownTypesAsListTypes)
yield return typeof(List<>).MakeGenericType(nullableType);
}
}
}
Expand Down

0 comments on commit 58de914

Please sign in to comment.