Matt,
This can be done quite easy. I made this change to clean the SQL char spaces. I have tested it and my code shows no signs if slowness due to the change.
First make sure that you back up your exiting source code so it will be easier to revert back should you need to.
Next Create the following method:
public static string ReadString(object value) /*** CUSTOM CODE ***/
{
if (value == null || value is DBNull) return null;
return value.ToString().Trim();
}
I always mark all my code changes with /* CUSTOM CODE */ so that I can later find my changes easily
Next find the following method:
public static void SetTypeMap(Type type, ITypeMap map)
now in that method locate the following lines:
if (memberType == typeof (char) || memberType == typeof (char?))
{
il.EmitCall(OpCodes.Call, typeof (SqlMapper).GetMethod(
memberType == typeof (char) ? "ReadChar" : "ReadNullableChar",
BindingFlags.Static | BindingFlags.Public), null);
// stack is now [target][target][typed-value]
}
else
and modify as follow:
if (memberType == typeof (char) || memberType == typeof (char?))
{
il.EmitCall(OpCodes.Call, typeof (SqlMapper).GetMethod(
memberType == typeof (char) ? "ReadChar" : "ReadNullableChar",
BindingFlags.Static | BindingFlags.Public), null);
// stack is now [target][target][typed-value]
}
else if (memberType == typeof(string)) /*** CUSTOM CODE START ***/
{
il.EmitCall(OpCodes.Call, typeof(SqlMapper).GetMethod("ReadString", BindingFlags.Static | BindingFlags.Public), null);
// stack is now [target][target][typed-value]
} /*** CUSTOM CODE END ***/
else
Compile and you are ready to go