예제 #1
0
        public static void CreateDefaultMethodImplementation(MethodDefinition methodInfo, ILProcessor il)
        {
            if (taskType.IsAssignableFrom(methodInfo.ReturnType))
            {
                if (methodInfo.ReturnType.IsTaskT())
                {
                    var returnTaskType = methodInfo.ReturnType.GetTaskType();
//                    if (returnTaskType.IsGenericParameter)

                    il.EmitDefaultValue(returnTaskType);
                    var fromResult = taskFromResult.MakeGenericMethod(returnTaskType);
                    il.Emit(OpCodes.Call, fromResult);
                }
                else
                {
                    il.Emit(OpCodes.Ldnull);
                    var fromResult = taskFromResult.MakeGenericMethod(ModuleDefinition.TypeSystem.Object);
                    il.Emit(OpCodes.Call, fromResult);
                }
            }
            else if (!methodInfo.ReturnType.CompareTo(ModuleDefinition.TypeSystem.Void))
            {
                il.EmitDefaultValue(methodInfo.ReturnType.Resolve());
            }

            // Return
            il.Emit(OpCodes.Ret);
        }