protected override void EmitSetImpl(CodeEmitter ilgen)
{
if(!IsStatic && DeclaringType.IsNonPrimitiveValueType)
{
CodeEmitterLocal temp = ilgen.DeclareLocal(FieldTypeWrapper.TypeAsSignatureType);
ilgen.Emit(OpCodes.Stloc, temp);
ilgen.Emit(OpCodes.Unbox, DeclaringType.TypeAsTBD);
ilgen.Emit(OpCodes.Ldloc, temp);
}
FieldInfo fi = GetField();
if(fi != null)
{
// common case (we're in a DynamicTypeWrapper and the caller is too)
ilgen.Emit(IsStatic ? OpCodes.Stsfld : OpCodes.Stfld, fi);
}
else
{
// this means that we are an instance on a CompiledTypeWrapper and we're being called
// from DynamicMethod based reflection, so we can safely emit a call to the private
// setter, because the DynamicMethod is allowed to access our private members.
ilgen.Emit(OpCodes.Call, prop.GetSetMethod(true));
}
}