IsGenericWebResult() public static méthode

public static IsGenericWebResult ( Type type ) : bool
type System.Type
Résultat bool
Exemple #1
0
        protected string GetRecursively(Type type, int pad, IEnumerable <CustomAttributeData> customAttributes)
        {
            if (type.IsGenericType && TypeBuilderHelper.IsGenericWebResult(type))
            {
                type = type.GetGenericArguments()[0];
            }

            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>))
            {
                return(null);
            }

            if (TypeBuilderHelper.IsArrayOrEnumerable(type))
            {
                var elementType = type.GetElementType() ?? type.GetGenericArguments()[0];

                if (SchemaTypeMapper.Map(elementType) != null)
                {
                    return(GetNestedArraySchemaPrimitiveType(pad, elementType));
                }

                if (elementType.IsGenericType && elementType.GetGenericTypeDefinition() == typeof(KeyValuePair <,>))
                {
                    return(GetNestedArraySchema(pad, elementType));
                }

                if (elementType.GetProperties().Count(p => p.CanRead || p.CanWrite) == 0)
                {
                    return(string.Empty);
                }

                return(GetNestedArraySchema(pad, elementType));
            }

            if (type.GetProperties().Count(p => p.CanRead || p.CanWrite) == 0)
            {
                return(string.Empty);
            }

            return(GetNestedObjectSchema(type, pad, customAttributes));
        }
Exemple #2
0
        public string Get(Type type)
        {
            definitions.Clear();
            Types.Clear();

            string schema;

            if (type.IsGenericType && TypeBuilderHelper.IsGenericWebResult(type))
            {
                type = type.GetGenericArguments()[0];
            }

            if (TypeBuilderHelper.IsArrayOrEnumerable(type))
            {
                var elementType = type.GetElementType() ?? type.GetGenericArguments()[0];
                if (elementType.GetProperties().Count(p => p.CanRead || p.CanWrite) == 0)
                {
                    return(null);
                }

                schema = GetArray(elementType);
            }
            else
            {
                if (type.GetProperties().Count(p => p.CanRead || p.CanWrite) == 0)
                {
                    return(null);
                }

                schema = GetMainObjectSchema(type);
            }

            schema = AddDefinitionsIfAny(schema);

            schema += "}" + Environment.NewLine;

            return(schema);
        }
        public string Add(Type type)
        {
            var typeName = GetTypeName(type);

            if (types.Contains(type))
            {
                return(typeName);
            }

            RamlType raml1Type;

            if (type.GetTypeInfo().IsGenericType&& TypeBuilderHelper.IsGenericWebResult(type))
            {
                type = type.GetGenericArguments()[0];
            }

            if (TypeBuilderHelper.IsArrayOrEnumerable(type))
            {
                var elementType = GetElementType(type);
                if (TypeBuilderHelper.IsArrayOrEnumerable(elementType))
                {
                    var subElementType = GetElementType(elementType);

                    if (Raml1TypeMapper.Map(subElementType) != null)
                    {
                        return(Raml1TypeMapper.Map(subElementType) + "[][]");
                    }

                    if (!HasPropertiesOrParentType(subElementType))
                    {
                        return(string.Empty);
                    }

                    types.Add(type);

                    raml1Type = GetArrayOfArray(subElementType);
                }
                else
                {
                    if (Raml1TypeMapper.Map(elementType) != null)
                    {
                        return(Raml1TypeMapper.Map(elementType) + "[]");
                    }

                    if (!HasPropertiesOrParentType(elementType))
                    {
                        return(string.Empty);
                    }

                    types.Add(type);

                    raml1Type = GetArray(elementType);
                }
            }
            else if (IsDictionary(type) || IsParentADictionary(type))
            {
                types.Add(type);
                raml1Type = GetMap(type);
            }
            else if (type.GetTypeInfo().IsEnum)
            {
                types.Add(type);
                raml1Type = GetEnum(type);
            }
            else if (Raml1TypeMapper.Map(type) != null)
            {
                //raml1Type = GetScalar(type);
                raml1Type = null;
                typeName  = Raml1TypeMapper.Map(type);
            }
            else
            {
                if (!HasPropertiesOrParentType(type))
                {
                    return(string.Empty);
                }

                types.Add(type);
                raml1Type = GetObject(type);
            }

            if (raml1Type != null)
            {
                AddType(type, raml1Type);
            }

            return(typeName);
        }