Commit 88766056 authored by Marc Gravell's avatar Marc Gravell

ISupportInitialize support

parent f5ae8e67
......@@ -2850,6 +2850,7 @@ public static void SetTypeMap(Type type, ITypeMap map)
ConstructorInfo specializedConstructor = null;
bool supportInitialize = false;
if (type.IsValueType)
{
il.Emit(OpCodes.Ldloca_S, (byte)1);
......@@ -2874,6 +2875,12 @@ public static void SetTypeMap(Type type, ITypeMap map)
{
il.Emit(OpCodes.Newobj, ctor);
il.Emit(OpCodes.Stloc_1);
supportInitialize = typeof(ISupportInitialize).IsAssignableFrom(type);
if(supportInitialize)
{
il.Emit(OpCodes.Ldloc_1);
il.EmitCall(OpCodes.Callvirt, typeof(ISupportInitialize).GetMethod("BeginInit"), null);
}
}
else
specializedConstructor = ctor;
......@@ -3120,6 +3127,11 @@ public static void SetTypeMap(Type type, ITypeMap map)
il.Emit(OpCodes.Newobj, specializedConstructor);
}
il.Emit(OpCodes.Stloc_1); // stack is empty
if (supportInitialize)
{
il.Emit(OpCodes.Ldloc_1);
il.EmitCall(OpCodes.Callvirt, typeof(ISupportInitialize).GetMethod("EndInit"), null);
}
}
il.MarkLabel(allDone);
il.BeginCatchBlock(typeof(Exception)); // stack is Exception
......
......@@ -2878,6 +2878,29 @@ public void DataTableParameters()
}
}
public void SupportInit()
{
var obj = connection.Query<WithInit>("select 'abc' as Value").Single();
obj.Value.Equals("abc");
obj.Flags.Equals(31);
}
class WithInit : ISupportInitialize
{
public string Value { get; set; }
public int Flags { get;set; }
void ISupportInitialize.BeginInit()
{
Flags += 1;
}
void ISupportInitialize.EndInit()
{
Flags += 30;
}
}
#if POSTGRESQL
class Cat
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment