TypeIsParameterlessDelegate() 공개 정적인 메소드

public static TypeIsParameterlessDelegate ( Type type ) : bool
type System.Type
리턴 bool
예제 #1
0
        private ActionDescriptorCreator GetActionDescriptorDelegate(MethodInfo entryMethod)
        {
            // Is this the BeginFoo() / EndFoo() pattern?
            if (entryMethod.Name.StartsWith("Begin", StringComparison.OrdinalIgnoreCase))
            {
                string     endMethodName = "End" + entryMethod.Name.Substring("Begin".Length);
                MethodInfo endMethod     = GetMethodByName(endMethodName);
                if (endMethod == null)
                {
                    string errorMessage = String.Format(CultureInfo.CurrentUICulture, MvcResources.ActionMethodSelector_CouldNotFindMethod, endMethodName, ControllerType.FullName);
                    throw new InvalidOperationException(errorMessage);
                }
                return((actionName, controllerDescriptor) => new ReflectedAsyncPatternActionDescriptor(entryMethod, endMethod, actionName, controllerDescriptor));
            }

            // Is this the Foo() / FooCompleted() pattern?
            {
                string     completionMethodName = entryMethod.Name + "Completed";
                MethodInfo completionMethod     = GetMethodByName(completionMethodName);
                if (completionMethod != null)
                {
                    return((actionName, controllerDescriptor) => new ReflectedEventPatternActionDescriptor(entryMethod, completionMethod, actionName, controllerDescriptor));
                }
            }

            // Does Foo() return a delegate that represents the continuation?
            if (TypeHelpers.TypeIsParameterlessDelegate(entryMethod.ReturnType))
            {
                return((actionName, controllerDescriptor) => new ReflectedDelegatePatternActionDescriptor(entryMethod, actionName, controllerDescriptor));
            }

            // Fallback to synchronous method
            return((actionName, controllerDescriptor) => new ReflectedActionDescriptor(entryMethod, actionName, controllerDescriptor));
        }
 private static void ValidateActionMethod(MethodInfo actionMethod)
 {
     if (actionMethod == null)
     {
         throw new ArgumentNullException("actionMethod");
     }
     else
     {
         if (!TypeHelpers.TypeIsParameterlessDelegate(actionMethod.ReturnType))
         {
             string message = String.Format(CultureInfo.CurrentUICulture,
                                            MvcResources.ReflectedDelegatePatternActionDescriptor_MethodHasWrongReturnType, actionMethod);
             throw new ArgumentException(message, "actionMethod");
         }
     }
 }