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 LocalBuilder LoadStructLocalBuilder(this ILGenerator il, Type type) { LocalBuilder tempBuidler = il.DeclareLocal(type); il.EmitStoreBuilder(tempBuidler); il.LoadBuilder(tempBuidler); return(tempBuidler); }
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); }