/// <summary>
        /// Parses the primary metadata about the method.
        /// </summary>
        public void Parse()
        {
            DirectiveLifeCycle lifeCycle;

            switch (this.Method.Name)
            {
            case Constants.ReservedNames.DIRECTIVE_BEFORE_RESOLUTION_METHOD_NAME:
                lifeCycle = DirectiveLifeCycle.BeforeResolution;
                break;

            case Constants.ReservedNames.DIRECTIVE_AFTER_RESOLUTION_METHOD_NAME:
                lifeCycle = DirectiveLifeCycle.AfterResolution;
                break;

            default:
                return;
            }

            this.IsValidDirectiveMethod = (this.Method.ReturnType == typeof(IGraphActionResult) || this.Method.ReturnType == typeof(Task <IGraphActionResult>)) &&
                                          !this.Method.IsGenericMethod;

            this.Description  = this.Method.SingleAttributeOrDefault <DescriptionAttribute>()?.Description;
            this.DeclaredType = this.Method.ReturnType;
            this.IsAsyncField = Validation.IsCastable <Task>(this.Method.ReturnType);

            // is the method asyncronous? if so ensure that a Task<T> is returned
            // and not an empty task
            if (this.IsAsyncField && this.Method.ReturnType.IsGenericType)
            {
                // for any ssync field attempt to pull out the T in Task<T>
                var genericArgs = this.Method.ReturnType.GetGenericArguments();
                if (genericArgs.Any())
                {
                    this.DeclaredType = genericArgs[0];
                }
            }

            this.ObjectType     = GraphValidation.EliminateWrappersFromCoreType(this.DeclaredType);
            this.LifeCycle      = lifeCycle;
            this.Route          = this.GenerateRoute();
            this.TypeExpression = new GraphTypeExpression(this.ObjectType.FriendlyName());

            // parse all input parameters into the method
            foreach (var parameter in this.Method.GetParameters())
            {
                var argTemplate = new GraphFieldArgumentTemplate(this, parameter);
                argTemplate.Parse();
                _arguments.Add(argTemplate);
            }

            this.MethodSignature = this.GenerateMethodSignatureString();

            this.ExpectedReturnType = GraphValidation.EliminateWrappersFromCoreType(
                this.DeclaredType,
                false,
                true,
                false);
        }
예제 #2
0
        /// <summary>
        /// When overridden in a child class this method builds out the template according to its own individual requirements.
        /// </summary>
        protected override void ParseTemplateDefinition()
        {
            base.ParseTemplateDefinition();

            // parse all input parameters into it
            foreach (var parameter in this.Method.GetParameters())
            {
                var argTemplate = new GraphFieldArgumentTemplate(this, parameter);
                argTemplate.Parse();
                _arguments.Add(argTemplate);
            }
        }