Esempio n. 1
0
        /// <summary>
        /// Applies the registered conventions.
        /// </summary>
        public void ApplyConventions()
        {
            lock (_registeredConventions)
            {
                if (!_registeredConventions.Any())
                {
                    return;
                }

                var types = new List <Type>();

                var filteredAssemblies = _assemblies.Where(assembly => AssemblyFilter.Matches(assembly));
                foreach (var filteredAssembly in filteredAssemblies)
                {
                    types.AddRange(TypeCache.GetTypesOfAssembly(filteredAssembly, type => !string.IsNullOrWhiteSpace(type.Namespace) && !type.Name.StartsWith("<")));
                }

                types.ForEach(RemoveIfAlreadyRegistered);

                var typesToHandle = types.Where(type => TypeFilter.Matches(type));

                _retrievedTypes = new HashSet <Type>(typesToHandle);

                if (!_retrievedTypes.Any())
                {
                    return;
                }

                _registeredConventions.ForEach(convention => convention.Process(_retrievedTypes));
            }
        }
        /// <summary>
        /// Applies the registered conventions.
        /// </summary>
        public void ApplyConventions()
        {
            lock (_registeredConventions)
            {
                if (!_registeredConventions.Any())
                {
                    return;
                }

                var types = _assemblies.Where(assembly => AssemblyFilter.Matches(assembly)).SelectMany(TypeCache.GetTypesOfAssembly).Where(type => !string.IsNullOrWhiteSpace(type.Namespace) && !type.Name.StartsWith("<"));

                var enumerable = types as Type[] ?? types.ToArray();

                enumerable.ForEach(RemoveIfAlreadyRegistered);

                var typesToHandle = enumerable.Where(type => TypeFilter.Matches(type));

                _retrievedTypes = new List <Type>(typesToHandle);

                if (!_retrievedTypes.Any())
                {
                    return;
                }

                _registeredConventions.ForEach(convention => convention.Process(_retrievedTypes));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new the MVC controllers info
        /// </summary>
        /// <param name="namedType">The named type for the controller</param>
        /// <param name="actionFilter">The parse filter to use for the MVC action attribute</param>
        /// <param name="typeFactory">The type table</param>
        internal MvcController(INamedType namedType, TypeFilter actionFilter, TypeFactory typeFactory)
        {
            NamedType    = namedType;
            _typeFactory = typeFactory;

            foreach (IMethod method in namedType.Methods)
            {
                if (method.Attributes.Any(attrData => actionFilter.Matches(attrData.AttributeType)))
                {
                    MvcAction action = new MvcAction(this, method, typeFactory);
                    _actions.Add(action);
                }
            }

            var baseType = NamedType.BaseType;

            while (baseType != null)
            {
                if (baseType.FullName == MvcConstants.ControllerBaseFullName_AspNetCore)
                {
                    IsAspNetCore = true;
                    break;
                }
                baseType = baseType.BaseType;
            }
        }
Esempio n. 4
0
        public string GetActionTemplate(MvcAction actionInfo)
        {
            var mvcAttr = actionInfo.Attributes.FirstOrDefault(attr => TypeFilter.Matches(attr.AttributeType));

            if (mvcAttr.ConstructorArguments.Count > 0)
            {
                return(mvcAttr.ConstructorArguments[0] as string);
            }
            return("");
        }
Esempio n. 5
0
            private bool TryFindSystemTextOverride(IProperty property, out string name)
            {
                name = null;
                var attr = property.Attributes.FirstOrDefault(a => s_systemTextJsonAttributeFilter.Matches(a.AttributeType));

                if (attr == null)
                {
                    return(false);
                }
                name = attr.ConstructorArguments[0] as string;
                return(true);
            }
Esempio n. 6
0
        private IAttributeData GetDisplayNameAttr(TypeFilter dispNameParseFilter)
        {
            string dispNameProvider = typeof(IEnumDisplayNameProvider).FullName;

            foreach (IAttributeData attr in Field.Attributes)
            {
                if (dispNameParseFilter.Matches(attr.AttributeType))
                {
                    return(attr);
                }
            }
            return(null);
        }
Esempio n. 7
0
        private List <TypeDescriptor> CompileTypes(IType memberType, IEnumerable <IAttributeData> memberAttributes, TypeFactory typeFactory)
        {
            var attr = memberAttributes.FirstOrDefault(a => s_scriptParamTypes.Matches(a.AttributeType));

            if (attr == null)
            {
                return(new List <TypeDescriptor>()
                {
                    typeFactory.LookupType(memberType)
                });
            }

            object[] typeArgs = attr.ConstructorArguments[0] as object[];

            return(typeArgs
                   .OfType <INamedType>()
                   .Select(arg => typeFactory.LookupType(arg))
                   .ToList());
        }
Esempio n. 8
0
            private bool TryFindNewtonsoftOverride(IProperty property, out string name)
            {
                name = null;
                var attr = property.Attributes.FirstOrDefault(a => s_newtonsoftJsonAttributeFilter.Matches(a.AttributeType));

                if (attr == null)
                {
                    return(false);
                }

                string jsonPropName = nameof(JsonProperty.PropertyName);

                if (!attr.NamedArguments.ContainsKey(jsonPropName))
                {
                    return(false);
                }

                name = attr.NamedArguments[jsonPropName] as string;
                return(true);
            }