コード例 #1
0
        public static TypeApiDescriptionModel Create(Type type)
        {
            var baseType = type.BaseType;

            if (baseType == typeof(object))
            {
                baseType = null;
            }

            var typeModel = new TypeApiDescriptionModel
            {
                IsEnum   = type.IsEnum,
                BaseType = baseType != null?ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(baseType) : null
            };

            if (typeModel.IsEnum)
            {
                typeModel.EnumNames  = type.GetEnumNames();
                typeModel.EnumValues = type.GetEnumValues().Cast <object>().ToArray();
            }
            else
            {
                typeModel.Properties = type
                                       .GetProperties()
                                       .Select(PropertyApiDescriptionModel.Create)
                                       .ToArray();
            }

            return(typeModel);
        }
コード例 #2
0
        //TODO: Validation rules for this property
        public static PropertyApiDescriptionModel Create(PropertyInfo propertyInfo)
        {
            string typeName;
            string simpleTypeName;

            if (TypeHelper.IsEnumerable(propertyInfo.PropertyType, out var itemType, includePrimitives: false))
            {
                typeName       = $"[{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(itemType)}]";
                simpleTypeName = $"[{ModelingTypeHelper.GetSimplifiedName(itemType)}]";
            }
コード例 #3
0
        public static ReturnValueApiDescriptionModel Create(Type type)
        {
            var unwrappedType = AsyncHelper.UnwrapTask(type);

            return(new ReturnValueApiDescriptionModel
            {
                Type = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(unwrappedType),
                TypeSimple = ModelingTypeHelper.GetSimplifiedName(unwrappedType)
            });
        }
コード例 #4
0
 public static MethodParameterApiDescriptionModel Create(ParameterInfo parameterInfo)
 {
     return(new MethodParameterApiDescriptionModel
     {
         Name = parameterInfo.Name,
         TypeAsString = parameterInfo.ParameterType.GetFullNameWithAssemblyName(),
         Type = parameterInfo.ParameterType != null?ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType) : null,
                    TypeSimple = parameterInfo.ParameterType != null?ModelingTypeHelper.GetSimplifiedName(parameterInfo.ParameterType) : null,
                                     IsOptional = parameterInfo.IsOptional,
                                     DefaultValue = parameterInfo.HasDefaultValue ? parameterInfo.DefaultValue : null
     });
 }
コード例 #5
0
 public static ParameterApiDescriptionModel Create(string name, string nameOnMethod, Type type, bool isOptional = false, object defaultValue = null, string[] constraintTypes = null, string bindingSourceId = null, string descriptorName = null)
 {
     return(new ParameterApiDescriptionModel
     {
         Name = name,
         NameOnMethod = nameOnMethod,
         Type = type != null?ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(type) : null,
                    TypeSimple = type != null?ModelingTypeHelper.GetSimplifiedName(type) : null,
                                     IsOptional = isOptional,
                                     DefaultValue = defaultValue,
                                     ConstraintTypes = constraintTypes,
                                     BindingSourceId = bindingSourceId,
                                     DescriptorName = descriptorName
     });
 }