private RamlType GetArray(Type elementType) { string elementTypeName; if (Raml1TypeMapper.Map(elementType) == null) { elementTypeName = Add(elementType); } else { elementTypeName = Raml1TypeMapper.Map(elementType); } if (string.IsNullOrWhiteSpace(elementTypeName)) { return(null); } return(new RamlType { Array = new ArrayType { Items = new RamlType { Name = GetTypeName(elementType), Type = elementTypeName } } }); }
private RamlType GetScalar(Type type) { var ramlType = new RamlType { Scalar = new Property { Type = Raml1TypeMapper.Map(type), } }; return(ramlType); }
private RamlType GetMap(Type type) { Type subtype; if (IsDictionary(type)) { subtype = type.GetGenericArguments()[1]; } else { subtype = type.GetTypeInfo().BaseType.GetGenericArguments()[1]; } var subtypeName = GetTypeName(subtype); if (Raml1TypeMapper.Map(subtype) != null) { subtypeName = Raml1TypeMapper.Map(subtype); } else { subtypeName = Add(subtype); } if (string.IsNullOrWhiteSpace(subtypeName)) { return(null); } var raml1Type = new RamlType { Object = new ObjectType { Properties = new Dictionary <string, RamlType>() { { "[]", new RamlType { Type = subtypeName, Required = true } } } } }; return(raml1Type); }
private RamlType GetProperty(PropertyInfo prop) { if (prop.PropertyType.GetTypeInfo().IsEnum) { return(GetEnum(prop.PropertyType)); } if (Raml1TypeMapper.Map(prop.PropertyType) != null) { return(HandlePrimitiveTypeProperty(prop)); } if (TypeBuilderHelper.IsArrayOrEnumerable(prop.PropertyType)) { return(GetArray(prop.PropertyType)); } if (IsDictionary(prop.PropertyType)) { return(GetMap(prop.PropertyType)); } return(HandleNestedTypeProperty(prop)); }
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); }
protected override string Map(Type type) { return(Raml1TypeMapper.Map(type)); }