il.Emit(OpCodes.Dup);// stack is now [parameters] [parameters]
il.Emit(OpCodes.Ldarg_0);// stack is now [parameters] [parameters] [command]
il.EmitCall(OpCodes.Callvirt,typeof(IDbCommand).GetMethod("CreateParameter"),null);// stack is now [parameters] [parameters] [parameter]
il.Emit(OpCodes.Dup);// stack is now [parameters] [parameters] [parameter] [parameter]
il.Emit(OpCodes.Ldstr,prop.Name);// stack is now [parameters] [parameters] [parameter] [parameter] [name]
il.EmitCall(OpCodes.Callvirt,typeof(IDataParameter).GetProperty("ParameterName").GetSetMethod(),null);// stack is now [parameters] [parameters] [parameter]
if(checkForDuplicates)
{
// need to be a little careful about adding; use a utility method
il.Emit(OpCodes.Ldstr,prop.Name);// stack is now [parameters] [parameters] [command] [name]
il.EmitCall(OpCodes.Call,typeof(SqlMapper).GetMethod("FindOrAddParameter"),null);// stack is [parameters] [parameter]
}
else
{
// no risk of duplicates; just blindly add
il.EmitCall(OpCodes.Callvirt,typeof(IDbCommand).GetMethod("CreateParameter"),null);// stack is now [parameters] [parameters] [parameter]
il.Emit(OpCodes.Dup);// stack is now [parameters] [parameters] [parameter] [parameter]
il.Emit(OpCodes.Ldstr,prop.Name);// stack is now [parameters] [parameters] [parameter] [parameter] [name]
il.EmitCall(OpCodes.Callvirt,typeof(IDataParameter).GetProperty("ParameterName").GetSetMethod(),null);// stack is now [parameters] [parameters] [parameter]
il.Emit(OpCodes.Dup);// stack is now [parameters] [parameters] [parameter] [parameter]
EmitInt32(il,(int)dbType);// stack is now [parameters] [parameters] [parameter] [parameter] [db-type]
il.Emit(OpCodes.Dup);// stack is now [parameters] [[parameters]] [parameter] [parameter]
EmitInt32(il,(int)dbType);// stack is now [parameters] [[parameters]] [parameter] [parameter] [db-type]
il.EmitCall(OpCodes.Callvirt,typeof(IDataParameter).GetProperty("DbType").GetSetMethod(),null);// stack is now [parameters] [parameters] [parameter]
il.EmitCall(OpCodes.Callvirt,typeof(IDataParameter).GetProperty("DbType").GetSetMethod(),null);// stack is now [parameters] [[parameters]] [parameter]
}
il.Emit(OpCodes.Dup);// stack is now [parameters] [parameters] [parameter] [parameter]
EmitInt32(il,(int)ParameterDirection.Input);// stack is now [parameters] [parameters] [parameter] [parameter] [dir]
il.EmitCall(OpCodes.Callvirt,typeof(IDataParameter).GetProperty("Direction").GetSetMethod(),null);// stack is now [parameters] [parameters] [parameter]
il.Emit(OpCodes.Dup);// stack is now [parameters] [[parameters]] [parameter] [parameter]
EmitInt32(il,(int)ParameterDirection.Input);// stack is now [parameters] [[parameters]] [parameter] [parameter] [dir]
il.EmitCall(OpCodes.Callvirt,typeof(IDataParameter).GetProperty("Direction").GetSetMethod(),null);// stack is now [parameters] [[parameters]] [parameter]
il.Emit(OpCodes.Dup);// stack is now [parameters] [parameters] [parameter] [parameter]
il.Emit(OpCodes.Ldloc_0);// stack is now [parameters] [parameters] [parameter] [parameter] [typed-param]
il.Emit(OpCodes.Callvirt,prop.GetGetMethod());// stack is [parameters] [parameters] [parameter] [parameter] [typed-value]
il.Emit(OpCodes.Dup);// stack is now [parameters] [[parameters]] [parameter] [parameter]
il.Emit(OpCodes.Ldloc_0);// stack is now [parameters] [[parameters]] [parameter] [parameter] [typed-param]
il.Emit(OpCodes.Callvirt,prop.GetGetMethod());// stack is [parameters] [[parameters]] [parameter] [parameter] [typed-value]
boolcheckForNull=true;
if(prop.PropertyType.IsValueType)
{
il.Emit(OpCodes.Box,prop.PropertyType);// stack is [parameters] [parameters] [parameter] [parameter] [boxed-value]
il.Emit(OpCodes.Box,prop.PropertyType);// stack is [parameters] [[parameters]] [parameter] [parameter] [boxed-value]