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;
        }
Ejemplo n.º 2
0
 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;
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
 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";
 }
Ejemplo n.º 6
0
 public static bool IsArray(this MetadataPropertyType prop)
 {
     return(prop.Type.IndexOf('[') >= 0);
 }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
 public static bool IsArray(this MetadataPropertyType prop)
 {
     return(prop.Type.SplitOnFirst('[').Length > 1);
 }
Ejemplo n.º 9
0
 public static bool IsCollection(this MetadataPropertyType prop) =>
 CollectionTypes.Contains(prop.Type) || IsArray(prop);
Ejemplo n.º 10
0
 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);
        }
Ejemplo n.º 12
0
        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;
        }
Ejemplo n.º 13
0
 protected bool IsPropertyTypeSupported(MetadataPropertyType type)
 {
     return(supportedPropertyTypes.Contains(type));
 }
Ejemplo n.º 14
0
        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";
        }
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 16
0
 public static bool IsArray(this MetadataPropertyType prop) =>
 prop.Type.IndexOf('[') >= 0;
Ejemplo n.º 17
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;
        }
Ejemplo n.º 18
0
        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);
        }