public MetadataPropertyType ToProperty(ParameterInfo pi) { var propertyAttrs = pi.AllAttributes(); var property = new MetadataPropertyType { Name = pi.Name, Attributes = ToAttributes(propertyAttrs), Type = pi.ParameterType.GetOperationName(), IsValueType = pi.ParameterType.IsValueType() ? true : (bool?)null, IsSystemType = pi.ParameterType.IsSystemType() ? true : (bool?)null, IsEnum = pi.ParameterType.IsEnum() ? true : (bool?)null, TypeNamespace = pi.ParameterType.Namespace, Description = pi.GetDescription(), }; return property; }
public static bool IsCollection(MetadataPropertyType prop) { return CollectionTypes.Contains(prop.Type) || prop.Type.SplitOnFirst('[').Length > 1; }
public MetadataPropertyType ToProperty(PropertyInfo pi, object instance = null) { var property = new MetadataPropertyType { Name = pi.Name, Attributes = ToAttributes(pi.GetCustomAttributes(false)), Type = pi.PropertyType.GetMetadataPropertyType(), IsValueType = pi.PropertyType.IsValueType() ? true : (bool?)null, IsSystemType = pi.PropertyType.IsSystemType() ? true : (bool?)null, IsEnum = pi.PropertyType.IsEnum() ? true : (bool?)null, TypeNamespace = pi.PropertyType.Namespace, DataMember = ToDataMember(pi.GetDataMember()), GenericArgs = pi.PropertyType.IsGenericType() ? pi.PropertyType.GetGenericArguments().Select(x => x.ExpandTypeName()).ToArray() : null, Description = pi.GetDescription(), }; var apiMember = pi.FirstAttribute<ApiMemberAttribute>(); if (apiMember != null) { if (apiMember.IsRequired) property.IsRequired = true; property.ParamType = apiMember.ParameterType; property.DisplayType = apiMember.DataType; } var apiAllowableValues = pi.FirstAttribute<ApiAllowableValuesAttribute>(); if (apiAllowableValues != null) { property.AllowableValues = apiAllowableValues.Values; property.AllowableMin = apiAllowableValues.Min; property.AllowableMax = apiAllowableValues.Max; } if (instance != null) { var value = pi.GetValue(instance, null); if (value != null && !value.Equals(pi.PropertyType.GetDefaultValue())) { if (pi.PropertyType.IsEnum()) { property.Value = "{0}.{1}".Fmt(pi.PropertyType.Name, value); } else if (pi.PropertyType == typeof(Type)) { var type = (Type)value; property.Value = $"typeof({type.FullName})"; } else { var strValue = value as string; property.Value = strValue ?? value.ToJson(); } } if (pi.GetSetMethod() == null) //ReadOnly is bool? to minimize serialization property.ReadOnly = true; } return property; }
public MetadataPropertyType ToProperty(ParameterInfo pi) { var propertyAttrs = pi.AllAttributes(); var property = new MetadataPropertyType { Name = pi.Name, Attributes = ToAttributes(propertyAttrs), Type = pi.ParameterType.GetOperationName(), Description = pi.GetDescription(), }; return property; }
private string GetDefaultLiteral(MetadataPropertyType prop) { var propType = Type(prop.Type, prop.GenericArgs); if (Config.InitializeCollections && prop.IsCollection()) { return prop.IsArray() ? "[||]" : "new {0}()".Fmt(propType); } return prop.IsValueType.GetValueOrDefault() ? "new {0}()".Fmt(propType) : "null"; }
public static bool IsArray(this MetadataPropertyType prop) { return(prop.Type.IndexOf('[') >= 0); }
public MetadataPropertyType ToProperty(PropertyInfo pi, object instance = null) { var property = new MetadataPropertyType { Name = pi.Name, Attributes = ToAttributes(pi.GetCustomAttributes(false)), Type = pi.PropertyType.GetOperationName(), DataMember = ToDataMember(pi.GetDataMember()), GenericArgs = pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericArguments().Select(x => x.GetOperationName()).ToArray() : null, }; if (instance != null) { var value = pi.GetValue(instance, null); if (value != null && !value.Equals(pi.PropertyType.GetDefaultValue())) { if (pi.PropertyType.IsEnum()) { property.Value = "{0}.{1}".Fmt(pi.PropertyType.Name, value); } else if (pi.PropertyType == typeof(Type)) { var type = (Type)value; property.Value = "typeof({0})".Fmt(type.FullName); } else { var strValue = value as string; property.Value = strValue ?? value.ToJson(); } } if (pi.GetSetMethod() == null) //ReadOnly is bool? to minimize serialization property.ReadOnly = true; } return property; }
public static bool IsArray(this MetadataPropertyType prop) { return(prop.Type.SplitOnFirst('[').Length > 1); }
public static bool IsCollection(this MetadataPropertyType prop) => CollectionTypes.Contains(prop.Type) || IsArray(prop);
public static bool IsCollection(MetadataPropertyType prop) { return(CollectionTypes.Contains(prop.Type) || prop.Type.SplitOnFirst('[').Length > 1); }
public MetadataPropertyType ToProperty(PropertyInfo pi, object instance = null) { var property = new MetadataPropertyType { Name = pi.Name, Attributes = ToAttributes(pi.GetCustomAttributes(false)), Type = pi.PropertyType.GetOperationName(), IsValueType = pi.PropertyType.IsValueType ? true : (bool?)null, TypeNamespace = pi.PropertyType.Namespace, DataMember = ToDataMember(pi.GetDataMember()), GenericArgs = pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericArguments().Select(x => x.ExpandTypeName()).ToArray() : null, Description = pi.GetDescription(), }; var apiMember = pi.FirstAttribute <ApiMemberAttribute>(); if (apiMember != null) { if (apiMember.IsRequired) { property.IsRequired = true; } property.ParamType = apiMember.ParameterType; property.DisplayType = apiMember.DataType; } var apiAllowableValues = pi.FirstAttribute <ApiAllowableValuesAttribute>(); if (apiAllowableValues != null) { property.AllowableValues = apiAllowableValues.Values; property.AllowableMin = apiAllowableValues.Min; property.AllowableMax = apiAllowableValues.Max; } if (instance != null) { var value = pi.GetValue(instance, null); if (value != null && !value.Equals(pi.PropertyType.GetDefaultValue())) { if (pi.PropertyType.IsEnum()) { property.Value = "{0}.{1}".Fmt(pi.PropertyType.Name, value); } else if (pi.PropertyType == typeof(Type)) { var type = (Type)value; property.Value = "typeof({0})".Fmt(type.FullName); } else { var strValue = value as string; property.Value = strValue ?? value.ToJson(); } } if (pi.GetSetMethod() == null) //ReadOnly is bool? to minimize serialization { property.ReadOnly = true; } } return(property); }
public static MetadataPropertyType ToProperty(this ParameterInfo pi) { var propertyAttrs = pi.AllAttributes(); var property = new MetadataPropertyType { Name = pi.Name, Attributes = propertyAttrs.ToAttributes(), Type = pi.ParameterType.GetComplexTypeName(), Description = pi.GetDescription(), }; return property; }
protected bool IsPropertyTypeSupported(MetadataPropertyType type) { return(supportedPropertyTypes.Contains(type)); }
private string GetDefaultLiteral(MetadataPropertyType prop, MetadataType type) { var propType = Type(prop.GetTypeName(Config, allTypes), prop.GenericArgs); var initCollections = feature.ShouldInitializeCollections(type, Config.InitializeCollections); if (initCollections && prop.IsCollection()) { return prop.IsArray() ? "[||]" : "new {0}()".Fmt(propType); } return prop.IsValueType.GetValueOrDefault() && propType != "String" ? "new {0}()".Fmt(propType) : "null"; }
public static MetadataPropertyType ToProperty(this PropertyInfo pi, object instance = null) { var property = new MetadataPropertyType { Name = pi.Name, Attributes = pi.GetCustomAttributes(false).ToAttributes(), Type = pi.PropertyType.Name, DataMember = pi.GetDataMember().ToDataMember(), GenericArgs = pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericArguments().Select(x => x.Name).ToArray() : null, }; if (instance != null) { var value = pi.GetValue(instance, null); if (value != pi.PropertyType.GetDefaultValue()) { property.Value = value.ToJson(); } } return property; }
public static bool IsArray(this MetadataPropertyType prop) => prop.Type.IndexOf('[') >= 0;
public static MetadataPropertyType ToProperty(this ParameterInfo pi) { var propertyAttrs = pi.GetCustomAttributes(false); var property = new MetadataPropertyType { Name = pi.Name, Attributes = propertyAttrs.ToAttributes(), Type = pi.ParameterType.Name, }; var descAttr = propertyAttrs.OfType<DescriptionAttribute>().FirstOrDefault(); if (descAttr != null) { property.Description = descAttr.Description; } return property; }
public static bool?DefaultIsPropertyOptional(TypeScriptGenerator generator, MetadataType type, MetadataPropertyType prop) { if (prop.Attributes.Safe().FirstOrDefault(x => x.Name == "Required") != null) { return(false); } if (generator.Config.MakePropertiesOptional) { return(true); } return(null); }