static void EmitInvokeCallback(Compiler.CompilerContext ctx, MethodInfo method, bool copyValue, Type constructType, Type type) { if (method != null) { if (copyValue) { ctx.CopyValue(); // assumes the target is on the stack, and that we want to *retain* it on the stack } ParameterInfo[] parameters = method.GetParameters(); bool handled = true; for (int i = 0; i < parameters.Length; i++) { Type parameterType = parameters[0].ParameterType; if (parameterType == ctx.MapType(typeof(SerializationContext))) { ctx.LoadSerializationContext(); } else if (parameterType == ctx.MapType(typeof(System.Type))) { Type tmp = constructType; if (tmp == null) { tmp = type; // no ?? in some C# profiles } ctx.LoadValue(tmp); } else if (parameterType == ctx.MapType(typeof(System.Runtime.Serialization.StreamingContext))) { ctx.LoadSerializationContext(); MethodInfo op = ctx.MapType(typeof(SerializationContext)).GetMethod("op_Implicit", new Type[] { ctx.MapType(typeof(SerializationContext)) }); if (op != null) { // it isn't always! (framework versions, etc) ctx.EmitCall(op); handled = true; } } else { handled = false; } } if (handled) { ctx.EmitCall(method); if (constructType != null) { if (method.ReturnType == ctx.MapType(typeof(object))) { ctx.CastFromObject(type); } } } else { throw Meta.CallbackSet.CreateInvalidCallbackSignature(method); } } }
static void EmitInvokeCallback(Compiler.CompilerContext ctx, MethodInfo method, bool copyValue) { if (method != null) { if (copyValue) { ctx.CopyValue(); // assumes the target is on the stack, and that we want to *retain* it on the stack } ParameterInfo[] parameters = method.GetParameters(); bool handled = false; switch (parameters.Length) { case 0: handled = true; break; case 1: Type parameterType = parameters[0].ParameterType; if (parameterType == ctx.MapType(typeof(SerializationContext))) { ctx.LoadSerializationContext(); handled = true; } #if PLAT_BINARYFORMATTER else if (parameterType == ctx.MapType(typeof(System.Runtime.Serialization.StreamingContext))) { ctx.LoadSerializationContext(); MethodInfo op = ctx.MapType(typeof(SerializationContext)).GetMethod("op_Implicit", new Type[] { ctx.MapType(typeof(SerializationContext)) }); if (op != null) { // it isn't always! (framework versions, etc) ctx.EmitCall(op); handled = true; } } #endif break; } if (!handled) { throw Meta.CallbackSet.CreateInvalidCallbackSignature(method); } ctx.EmitCall(method); } }