public static void LoadPrivateProperty(this ILGenerator il, Action thisInStack, PropertyInfo info) { //加载GetValue的第一个参数 即PropertyInfo il.REmit(OpCodes.Ldtoken, info.DeclaringType); il.REmit(OpCodes.Call, ClassCache.ClassHandle); il.REmit(OpCodes.Ldstr, info.Name); il.REmit(OpCodes.Ldc_I4_S, 60); il.REmit(OpCodes.Callvirt, ClassCache.PropertyInfoGetter); //加载GetValue的第二个参数 if (thisInStack != null) { thisInStack(); } ; il.Packet(info.DeclaringType); //调用GetValue il.REmit(OpCodes.Callvirt, ClassCache.PropertyValueGetter); il.UnPacket(info.PropertyType); if (info.PropertyType.IsValueType && !info.PropertyType.IsPrimitive) { LocalBuilder builder = il.DeclareLocal(info.PropertyType); il.EmitStoreBuilder(builder); il.LoadBuilder(builder); } il.BoolInStack(info.PropertyType); //il.CallNullableValue(info.PropertyType,true); }
//public static void CallNullableValue(this ILGenerator il, Type type,bool IsProperty=false) //{ // if (il.IsNullable(type)) // { // //PropertyInfo info = type.GetProperty("Value"); // if (IsProperty) // { // LocalBuilder tempBuidler = il.DeclareLocal(type); // il.EmitStoreBuilder(tempBuidler); // il.LoadBuilder(tempBuidler); // } // MethodInfo value = type.GetMethod("GetValueOrDefault",new Type[0]); // MethodHelper.CallMethod(value); // //EJudge.If(()=> { MethodHelper.CallMethod(hashInfo.GetGetMethod(true)); il.BoolInStack(typeof(bool)); })(() => { // // MethodHelper.CallMethod(info.GetGetMethod(true)); // // //il.BoolInStack(type.GenericTypeArguments[0]); // // il.LoadOne(type.GenericTypeArguments[0]); // //}).Else(() => { // // il.LoadOne(type.GenericTypeArguments[0]); // //}); // } //} #region 属性操作 public static void LoadPublicPropertyValue(this ILGenerator il, Action thisInStack, PropertyInfo info) { MethodInfo method = info.GetGetMethod(true); //静态属性 if (!method.IsStatic) { thisInStack(); } MethodHelper.CallMethod(method); il.BoolInStack(info.PropertyType); //il.CallNullableValue(info.PropertyType,true); }
//设置公有结构体字段 public static void LoadPublicField(this ILGenerator il, Action thisInStack, FieldInfo info) { if (info.IsStatic) { il.REmit(OpCodes.Ldsflda, info); } else { if (thisInStack != null) { thisInStack(); } il.REmit(OpCodes.Ldflda, info); } il.BoolInStack(info.FieldType); //il.CallNullableValue(info.FieldType); }
public static void LoadPublicProperty(this ILGenerator il, Action thisInStack, PropertyInfo info) { MethodInfo method = info.GetGetMethod(true); //静态属性 if (!method.IsStatic) { thisInStack(); } MethodHelper.CallMethod(method); if (info.PropertyType.IsValueType && !info.PropertyType.IsPrimitive) { LocalBuilder builder = il.DeclareLocal(info.PropertyType); il.EmitStoreBuilder(builder); il.LoadBuilder(builder); } il.BoolInStack(info.PropertyType); //il.CallNullableValue(info.PropertyType,true); }
//加载私有字段 public static void LoadPrivateFieldValue(this ILGenerator il, Action thisInStack, FieldInfo info) { //加载GetValue的第一个参数 即FieldInfo il.REmit(OpCodes.Ldtoken, info.DeclaringType); il.REmit(OpCodes.Call, ClassCache.ClassHandle); il.REmit(OpCodes.Ldstr, info.Name); il.REmit(OpCodes.Ldc_I4_S, 44); il.REmit(OpCodes.Callvirt, ClassCache.FieldInfoGetter); //加载GetValue的第二个参数 if (thisInStack != null) { thisInStack(); } il.Packet(info.DeclaringType); //调用GetValue il.REmit(OpCodes.Callvirt, ClassCache.FieldValueGetter); //拆箱 il.UnPacket(info.FieldType); il.BoolInStack(info.FieldType); }