Skip to content

Commit e20eff1

Browse files
NH-3964 - remove obsolete workaround implying some reflection.
1 parent a412e39 commit e20eff1

File tree

3 files changed

+20
-32
lines changed

3 files changed

+20
-32
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections;
2+
using NHibernate.Util;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.NHSpecificTest.NH3964
6+
{
7+
[TestFixture]
8+
public class Fixture
9+
{
10+
[Test(Description = "Test for removal of a workaround for an old Fx bug (<v4)")]
11+
public void AddingNullToNonGenericListShouldNotThrow()
12+
{
13+
var a1 = new ArrayList { null };
14+
var a2 = new ArrayList();
15+
Assert.DoesNotThrow(() => ArrayHelper.AddAll(a2, a1));
16+
}
17+
}
18+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@
742742
<Compile Include="NHSpecificTest\NH3961\DateParametersComparedTo.cs" />
743743
<Compile Include="NHSpecificTest\NH3963\Entity.cs" />
744744
<Compile Include="NHSpecificTest\NH3963\MappedAsFixture.cs" />
745+
<Compile Include="NHSpecificTest\NH3964\Fixture.cs" />
745746
<Compile Include="NHSpecificTest\NH3950\Entity.cs" />
746747
<Compile Include="NHSpecificTest\NH3950\Fixture.cs" />
747748
<Compile Include="NHSpecificTest\NH3952\Entity.cs" />

src/NHibernate/Util/ArrayHelper.cs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -95,40 +95,9 @@ public static string ToString(object[] array)
9595
/// <param name="from"></param>
9696
public static void AddAll(IList to, IList from)
9797
{
98-
System.Action addNull = null;
9998
foreach (object obj in from)
10099
{
101-
// There is bug in .NET, before version 4, where adding null to a List<Nullable<T>> through the non-generic IList interface throws an exception.
102-
// TODO: Everything but the to.Add(obj) should be conditionally compiled only for versions of .NET earlier than 4.
103-
if (obj == null)
104-
{
105-
if (addNull == null)
106-
{
107-
var toType = to.GetType();
108-
if (toType.IsGenericType &&
109-
toType.GetGenericTypeDefinition() == typeof(List<>) &&
110-
toType.GetGenericArguments()[0].IsNullable())
111-
{
112-
MethodInfo addMethod = toType.GetMethod("Add");
113-
var addMethodCall = System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression.Constant(to),
114-
addMethod,
115-
System.Linq.Expressions.Expression.Constant(null, toType.GetGenericArguments()[0]));
116-
System.Linq.Expressions.LambdaExpression addLambda =
117-
System.Linq.Expressions.Expression.Lambda(addMethodCall);
118-
119-
addNull = (System.Action)addLambda.Compile();
120-
}
121-
else
122-
{
123-
addNull = () => to.Add(null);
124-
}
125-
}
126-
addNull();
127-
}
128-
else
129-
{
130-
to.Add(obj);
131-
}
100+
to.Add(obj);
132101
}
133102
}
134103

0 commit comments

Comments
 (0)