Permalink
Browse files

Fix for actlike proxy null comparison, Added support for dbnull coerc…

…ion.
  • Loading branch information...
1 parent 94a60c3 commit 7181a01986fbd7ed2615bc6fcd697f042674f042 jayt committed Aug 15, 2012
@@ -66,7 +66,7 @@ public abstract class ActLikeProxy : IActLikeProxyInitialize, ISerializable
/// <param name="informalInterface"></param>
void IActLikeProxyInitialize.Initialize(dynamic original, IEnumerable<Type> interfaces, IDictionary<string, Type> informalInterface)
{
- if(original == null)
+ if(((object)original) == null)
throw new ArgumentNullException("original", "Can't proxy a Null value");
if (_init)
@@ -691,7 +691,7 @@ public static dynamic InvokeConvert(object target, Type type, bool @explicit =fa
public static dynamic CoerceConvert(object target, Type type)
{
- if (target != null && !type.IsInstanceOfType(target))
+ if (target != null && !type.IsInstanceOfType(target) && DBNull.Value != target)
{
if (type.IsInterface)
@@ -785,9 +785,12 @@ public static dynamic CoerceConvert(object target, Type type)
}
}
}
- else if (target == null && type.IsValueType)
+ else if (((target == null)|| target == DBNull.Value)&& type.IsValueType)
{
target = Impromptu.InvokeConstructor(type);
+ }else if(!type.IsInstanceOfType(target) && DBNull.Value == target)
+ {
+ return null;
}
return target;
}
@@ -135,8 +135,17 @@ public void AreEqual(dynamic expected, dynamic actual)
return;
if(expected ==null || !expected.Equals(actual))
FailExpected(expected, actual);
+ }
+
+ public void AreNotEqual(dynamic expected, dynamic actual)
+ {
+ if (expected == null && actual != null)
+ return;
+ if (expected == null || expected.Equals(actual))
+ FailExpected(expected, actual);
}
+
public void Less(dynamic smaller, dynamic larger)
{
@@ -341,6 +341,24 @@ public void TestImplicitConvert()
Assert.AreEqual(typeof(long), tCast.GetType());
}
+
+ [Test]
+ public void TestCoerceConverterDBNULL()
+ {
+ var tEl = DBNull.Value;
+
+ var tCast = Impromptu.CoerceConvert(tEl, typeof(long));
+
+ Assert.AreEqual(typeof(long), tCast.GetType());
+
+ var tCast2 = Impromptu.CoerceConvert(tEl, typeof(string));
+ Assert.AreEqual(null, tCast2);
+
+ Assert.AreNotEqual(null, tEl);
+ }
+
+
+
[Test]
public void TestCacheableImplicitConvert()
{

0 comments on commit 7181a01

Please sign in to comment.