Пример #1
0
        private List <object> MapAnnotationsToAttributes(ReflectedMethodInfo scriptMethodInfo)
        {
            var annotations = scriptMethodInfo.GetCustomAttributes(typeof(UserAnnotationAttribute), false)
                              .Select(x => ((UserAnnotationAttribute)x).Annotation);

            return(MapAnnotationsToAttributes(annotations));
        }
        private void CorrectDispId(ReflectedMethodInfo scriptMethodInfo)
        {
            var fieldId = typeof(ReflectedMethodInfo).GetField("_dispId",
                                                               BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField);

            var currId = (int)fieldId.GetValue(scriptMethodInfo);

            currId += _controllersMethodOffset;
            fieldId.SetValue(scriptMethodInfo, currId);
        }
Пример #3
0
 private static System.Reflection.MethodInfo MapToActionMethod(ReflectedMethodInfo reflectedMethodInfo)
 {
     System.Reflection.MethodInfo clrMethodInfo;
     if (reflectedMethodInfo.IsFunction)
     {
         clrMethodInfo = typeof(ScriptedController).GetMethod("ResultAction");
     }
     else
     {
         clrMethodInfo = typeof(ScriptedController).GetMethod("VoidAction");
     }
     return(clrMethodInfo);
 }
Пример #4
0
        private ReflectedMethodInfo CreateMethodInfo(MethodInfo methInfo)
        {
            var reflectedMethod = new ReflectedMethodInfo(methInfo.Name);

            reflectedMethod.SetPrivate(!methInfo.IsExport);
            reflectedMethod.IsFunction = methInfo.IsFunction;

            for (int i = 0; i < methInfo.Params.Length; i++)
            {
                var currentParam   = methInfo.Params[i];
                var reflectedParam = new ReflectedParamInfo(currentParam.Name, currentParam.IsByValue);
                reflectedParam.SetOwner(reflectedMethod);
                reflectedParam.SetPosition(i);
                reflectedMethod.Parameters.Add(reflectedParam);
            }

            return(reflectedMethod);
        }
Пример #5
0
        private ReflectedMethodInfo CreateMethodInfo(MethodInfo methInfo)
        {
            var reflectedMethod = new ReflectedMethodInfo(methInfo.Name);

            reflectedMethod.SetPrivate(!methInfo.IsExport);
            reflectedMethod.IsFunction = methInfo.IsFunction;

            var unknownVal = ValueFactory.CreateInvalidValueMarker();

            for (int i = 0; i < methInfo.Params.Length; i++)
            {
                var currentParam   = methInfo.Params[i];
                var reflectedParam = new ReflectedParamInfo(currentParam.Name, currentParam.IsByValue);
                reflectedParam.SetOwner(reflectedMethod);
                reflectedParam.SetPosition(i);
                if (currentParam.HasDefaultValue)
                {
                }

                reflectedParam.SetDefaultValue(unknownVal);
                if (currentParam.Annotations != null)
                {
                    foreach (var annotation in currentParam.Annotations)
                    {
                        reflectedParam.AddAnnotation(annotation);
                    }
                }

                reflectedMethod.Parameters.Add(reflectedParam);
            }

            if (methInfo.Annotations != null)
            {
                foreach (var annotation in methInfo.Annotations)
                {
                    reflectedMethod.AddAnnotation(annotation);
                }
            }

            return(reflectedMethod);
        }
Пример #6
0
        private void BuildMethodRow(XDoc html, ReflectedMethodInfo member)
        {
            var xmlDoc = GetDoc(member.Signature);

            html.Start("tr")
            .Elem("td", member.MemberAccess)
            .Start("td").StartSpan("member");
            if (IsTypeInDocumentation(member.DeclaringType))
            {
                html.Link(member.UriPath, member.DisplayName);
            }
            else
            {
                html.Value(member.DisplayName);
            }
            html
            .EndSpan()
            .StartSpan("description");
            if (member.IsOverride && !member.IsInherited)
            {
                html.Value("(Override)");
            }
            if (member.IsExtensionMethod)
            {
                html.Value("(Extension)");
            }
            html.AddNodes(xmlDoc["summary"]);
            if (member.IsInherited)
            {
                html.Value(string.Format("(Inherited from {0})", member.DeclaringType.DisplayName));
            }
            html
            .EndSpan()
            .End()      // td
            .End();     // tr
        }
        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);
        }
Пример #8
0
 private ReflectedMethodInfo BuildMethodInfo(ReflectedTypeInfo typeInfo, MethodInfo method)
 {
     var isNewSlot = ((method.Attributes & MethodAttributes.NewSlot) == MethodAttributes.NewSlot);
     var isReusedSlot = ((method.Attributes & MethodAttributes.ReuseSlot) == MethodAttributes.ReuseSlot);
     var isOverride = method.IsVirtual && !isNewSlot && isReusedSlot;
     var methodInfo = new ReflectedMethodInfo() {
         Name = method.Name,
         Type = typeInfo,
         DeclaringType = GetType(method.DeclaringType),
         IsOverride = isOverride,
         MemberAccess = DetermineAccess(method),
         IsVirtual = method.IsVirtual && !isOverride,
         IsStatic = method.IsStatic,
         IsExtensionMethod = method.GetCustomAttributes(typeof(ExtensionAttribute), false).Any()
     };
     var parameterBuilder = new ParameterBuilder(methodInfo, GetType);
     if(method.IsGenericMethod) {
         var genericArgs = method.GetGenericArguments();
         methodInfo.IsGenericMethod = true;
         methodInfo.GenericParameters = GetGenericParameters(genericArgs, true);
         for(int i = 0; i < genericArgs.Length; i++) {
             foreach(var constraintType in genericArgs[i].GetGenericParameterConstraints()) {
                 if(constraintType == typeof(ValueType)) {
                     continue;
                 }
                 methodInfo.GenericParameters[i].Types.Add(parameterBuilder.BuildType(constraintType));
             }
         }
     }
     methodInfo.ReturnType = parameterBuilder.BuildType(method.ReturnType);
     methodInfo.Parameters = GetParameters(method.GetParameters(), parameterBuilder);
     if(methodInfo.IsExtensionMethod) {
         methodInfo.Parameters[0].IsExtensionParameter = true;
     }
     return methodInfo;
 }