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); }
//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)}]"; }
public static ReturnValueApiDescriptionModel Create(Type type) { var unwrappedType = AsyncHelper.UnwrapTask(type); return(new ReturnValueApiDescriptionModel { Type = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(unwrappedType), TypeSimple = ModelingTypeHelper.GetSimplifiedName(unwrappedType) }); }
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 }); }
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 }); }