public static GetMethodName ( MethodInfo info ) : string | ||
info | MethodInfo | |
Résultat | string |
public static Action <T, V> GetEmitSet(MethodInfo info) { if (info == null) { return(null); } DynamicMethod method = new DynamicMethod(EmitInvoker.GetMethodName(info), typeof(void), new Type[] { typeof(T), typeof(V) }, info.DeclaringType, true); var il = method.GetILGenerator(); if (!info.IsStatic) { il.Emit(OpCodes.Ldarg_0); } il.Emit(OpCodes.Ldarg_1); if (info.IsStatic) { il.EmitCall(OpCodes.Call, info, null); } else { il.EmitCall(OpCodes.Callvirt, info, null); } il.Emit(OpCodes.Ret); return((Action <T, V>)method.CreateDelegate(typeof(Action <T, V>))); }
public static Func <T, V> GetEmitGet(MethodInfo info) { var method = new DynamicMethod(EmitInvoker.GetMethodName(info), typeof(V), new Type[] { typeof(T) }, info.DeclaringType, true); ILGenerator il = method.GetILGenerator(); if (!info.IsStatic) { il.Emit(OpCodes.Ldarg_0); } if (info.IsStatic) { il.EmitCall(OpCodes.Call, info, null); } else { il.EmitCall(OpCodes.Callvirt, info, null); } il.Emit(OpCodes.Ret); return((Func <T, V>)method.CreateDelegate(typeof(Func <T, V>))); }
public static Func <T, K, V> GetInvokerGet(MethodInfo info) { var ps = info.GetParameters(); var method = new DynamicMethod(EmitInvoker.GetMethodName(info), typeof(V), new Type[] { typeof(T), typeof(K) }, true); ILGenerator il = method.GetILGenerator(); if (!info.IsStatic) { il.Emit(OpCodes.Ldarg_0); } if (ps.Length > 0) { il.Emit(OpCodes.Ldarg_1); } for (int i = 1; i < ps.Length; i++) { //if (ps[i].ParameterType.IsByRef) // il.Emit(OpCodes.Ldloca_S, locals[i - 1]); //else // il.Emit(OpCodes.Ldloc, locals[i - 1]); if (ps[i].DefaultValue is Enum) { EmitInvoker.EmitFastInt(il, (int)ps[i].DefaultValue); //EmitCastToReference(il, ps[i].ParameterType); //il.Emit(OpCodes.Castclass, ps[i].ParameterType); } else if (ps[i].DefaultValue is int) { EmitInvoker.EmitFastInt(il, (int)ps[i].DefaultValue); } else if (ps[i].DefaultValue is string) { il.Emit(OpCodes.Ldstr, (string)ps[i].DefaultValue); } else if (ps[i].DefaultValue == null) { il.Emit(OpCodes.Ldnull); } } if (info.IsStatic) { il.EmitCall(OpCodes.Call, info, null); } else { il.EmitCall(OpCodes.Callvirt, info, null); } il.Emit(OpCodes.Ret); return((Func <T, K, V>)method.CreateDelegate(typeof(Func <T, K, V>))); }
private GetHandler <T, V> GetInvokerGet(MethodInfo info) { var method = new DynamicMethod(EmitInvoker.GetMethodName(info), typeof(V), new Type[] { typeof(T) }, true); ILGenerator il = method.GetILGenerator(); if (!info.IsStatic) { il.Emit(OpCodes.Ldarga_S, 0); //il.Emit(OpCodes.Ldind_Ref); } il.EmitCall(OpCodes.Call, info, null); il.Emit(OpCodes.Ret); return((GetHandler <T, V>)method.CreateDelegate(typeof(GetHandler <T, V>))); }
public static Action <T, K, V> GetInvokerSet(MethodInfo info) { DynamicMethod method = new DynamicMethod(EmitInvoker.GetMethodName(info), typeof(void), new Type[] { typeof(T), typeof(K), typeof(V) }, true); var ps = info.GetParameters(); var il = method.GetILGenerator(); if (!info.IsStatic) { il.Emit(OpCodes.Ldarg_0); } if (ps.Length > 0) { il.Emit(OpCodes.Ldarg_1); } if (ps.Length > 1) { il.Emit(OpCodes.Ldarg_2); } for (int i = 2; i < ps.Length; i++) { //if (ps[i].ParameterType.IsByRef) // il.Emit(OpCodes.Ldloca_S, locals[i - 2]); //else // il.Emit(OpCodes.Ldloc, locals[i - 2]); } if (info.IsStatic) { il.EmitCall(OpCodes.Call, info, null); } else { il.EmitCall(OpCodes.Callvirt, info, null); } il.Emit(OpCodes.Ret); return((Action <T, K, V>)method.CreateDelegate(typeof(Action <T, K, V>))); }
public static Func <T, object[], V> GetMethodInvoker(MethodInfo info) { var method = new DynamicMethod(EmitInvoker.GetMethodName(info), typeof(V), new Type[] { typeof(T), typeof(object[]) }, true); var il = method.GetILGenerator(); var ps = info.GetParameters(); var paramTypes = new Type[ps.Length]; var locals = new LocalBuilder[paramTypes.Length]; for (int i = 0; i < paramTypes.Length; i++) { if (ps[i].ParameterType.IsByRef) { paramTypes[i] = ps[i].ParameterType.GetElementType(); } else { paramTypes[i] = ps[i].ParameterType; } } for (int i = 0; i < paramTypes.Length; i++) { locals[i] = il.DeclareLocal(paramTypes[i], true); } for (int i = 0; i < paramTypes.Length; i++) { il.Emit(OpCodes.Ldarg_1); EmitInvoker.EmitFastInt(il, i); il.Emit(OpCodes.Ldelem_Ref); EmitInvoker.EmitCastToReference(il, paramTypes[i]); il.Emit(OpCodes.Stloc, locals[i]); } if (!info.IsStatic) { il.Emit(OpCodes.Ldarg_0); } for (int i = 0; i < paramTypes.Length; i++) { if (ps[i].ParameterType.IsByRef) { il.Emit(OpCodes.Ldloca_S, locals[i]); } else { il.Emit(OpCodes.Ldloc, locals[i]); } } if (info.IsStatic) { il.EmitCall(OpCodes.Call, info, null); } else { il.EmitCall(OpCodes.Callvirt, info, null); } if (info.ReturnType == typeof(void)) { il.Emit(OpCodes.Ldnull); } for (int i = 0; i < paramTypes.Length; i++) { if (ps[i].ParameterType.IsByRef) { il.Emit(OpCodes.Ldarg_1); EmitInvoker.EmitFastInt(il, i); il.Emit(OpCodes.Ldloc, locals[i]); if (locals[i].LocalType.IsValueType) { il.Emit(OpCodes.Box, locals[i].LocalType); } il.Emit(OpCodes.Stelem_Ref); } } il.Emit(OpCodes.Ret); return((Func <T, object[], V>)method.CreateDelegate(typeof(Func <T, object[], V>))); }