コード例 #1
0
        private List <object> MapAnnotationsToAttributes(ReflectedMethodInfo scriptMethodInfo)
        {
            var annotations = scriptMethodInfo.GetCustomAttributes(typeof(UserAnnotationAttribute), false)
                              .Select(x => ((UserAnnotationAttribute)x).Annotation);

            return(MapAnnotationsToAttributes(annotations));
        }
コード例 #2
0
        private ActionModel CreateActionModel(ReflectedMethodInfo scriptMethodInfo)
        {
            var clrMethodInfo   = MapToActionMethod(scriptMethodInfo);
            var userAnnotations = scriptMethodInfo.GetCustomAttributes(typeof(UserAnnotationAttribute), false)
                                  .Select(x => ((UserAnnotationAttribute)x).Annotation);

            string actionName      = scriptMethodInfo.Name;
            string magicHttpMethod = null;
            List <AnnotationDefinition> workSet = new List <AnnotationDefinition>();

            var pos = actionName.LastIndexOf('_');

            if (pos > 0 && pos < actionName.Length - 1)
            {
                magicHttpMethod = actionName.Substring(pos + 1);
            }

            foreach (var annotation in userAnnotations)
            {
                var loCase         = annotation.Name.ToLowerInvariant();
                var workAnnotation = annotation;
                if (loCase == "httpmethod")
                {
                    if (magicHttpMethod != null)
                    {
                        if (annotation.ParamCount == 0)
                        {
                            // наш случай.
                            actionName = actionName.Substring(0, pos);
                            workAnnotation.Parameters = new[]
                            {
                                new AnnotationParameter()
                                {
                                    Name         = "Method",
                                    RuntimeValue = ValueFactory.Create(magicHttpMethod)
                                }
                            };
                        }
                    }
                }

                workSet.Add(workAnnotation);
            }

            var attrList            = MapAnnotationsToAttributes(workSet);
            var annotatedActionName = attrList.OfType <ActionNameAttribute>().FirstOrDefault();

            if (annotatedActionName?.Name != null)
            {
                actionName = annotatedActionName.Name;
            }

            var actionModel = new ActionModel(clrMethodInfo, attrList.AsReadOnly());

            actionModel.ActionName = actionName;
            actionModel.Properties.Add("actionMethod", scriptMethodInfo);
            foreach (var selector in CreateSelectors(actionModel.Attributes))
            {
                actionModel.Selectors.Add(selector);
            }

            return(actionModel);
        }