/// <summary>
        /// Process the type parameters for a given type.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> to process.</param>
        /// <returns>The list of parsed type parameters.</returns>
        private IList <DocTypeParameter> ProcessTypeParameters(Type type)
        {
            var result = new List <DocTypeParameter>();

            if (type.IsGenericType)
            {
                foreach (var tParam in type.GetGenericArguments().Where(t => t.IsGenericParameter))
                {
                    var docParameter = new DocTypeParameter {
                        Name = tParam.Name
                    };
                    MemberUtils.ParseGenericTypeConstraints(tParam, docParameter);
                    result.Add(docParameter);
                }
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list of generic type constraints.
        /// </summary>
        /// <param name="type">The <see cref="Type"/> to parse.</param>
        /// <param name="docType">The <see cref="DocTypeParameter"/> to parse to.</param>
        public static void ParseGenericTypeConstraints(Type type, DocTypeParameter docType)
        {
            docType.IsContravariant = (type.GenericParameterAttributes & GenericParameterAttributes.Contravariant) > 0;
            docType.IsCovariant     = (type.GenericParameterAttributes & GenericParameterAttributes.Contravariant) > 0;
            foreach (var attribute in BuiltInConstraints)
            {
                if ((type.GenericParameterAttributes & attribute.Key) > 0)
                {
                    docType.TypeConstraints.Add(new TypeRef {
                        FriendlyName = string.Format(attribute.Value, $"`{TypeCache.Cache[type].FriendlyName}`")
                    });
                }
            }

            foreach (var constraint in type.GetGenericParameterConstraints())
            {
                docType.TypeConstraints.Add(TypeCache.Cache[constraint]);
            }
        }