public static ReturnValueApiDescriptionModel Create(Type type) { var unwrappedType = AsyncHelper.UnwrapTask(type); return(new ReturnValueApiDescriptionModel { Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(unwrappedType), TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(unwrappedType) }); }
//TODO: Validation rules for this property public static PropertyApiDescriptionModel Create(PropertyInfo propertyInfo) { return(new PropertyApiDescriptionModel { Name = propertyInfo.Name, JsonName = AbpApiProxyScriptingConfiguration.PropertyNameGenerator.Invoke(propertyInfo), Type = ApiTypeNameHelper.GetTypeName(propertyInfo.PropertyType), TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(propertyInfo.PropertyType), IsRequired = propertyInfo.IsDefined(typeof(RequiredAttribute), true) }); }
public static MethodParameterApiDescriptionModel Create(ParameterInfo parameterInfo) { return(new MethodParameterApiDescriptionModel { Name = parameterInfo.Name, TypeAsString = parameterInfo.ParameterType.GetFullNameWithAssemblyName(), Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType), TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(parameterInfo.ParameterType), IsOptional = parameterInfo.IsOptional, DefaultValue = parameterInfo.HasDefaultValue ? parameterInfo.DefaultValue : null }); }
public static ParameterApiDescriptionModel Create(string name, string jsonName, string nameOnMethod, Type type, bool isOptional = false, object defaultValue = null, string[] constraintTypes = null, string bindingSourceId = null, string descriptorName = null) { return(new ParameterApiDescriptionModel { Name = name, JsonName = jsonName, NameOnMethod = nameOnMethod, Type = type != null?TypeHelper.GetFullNameHandlingNullableAndGenerics(type) : null, TypeSimple = type != null?ApiTypeNameHelper.GetSimpleTypeName(type) : null, IsOptional = isOptional, DefaultValue = defaultValue, ConstraintTypes = constraintTypes, BindingSourceId = bindingSourceId, DescriptorName = descriptorName }); }
public static PropertyApiDescriptionModel Create(PropertyInfo propertyInfo) { var customAttributes = propertyInfo.GetCustomAttributes(true); return(new PropertyApiDescriptionModel { Name = propertyInfo.Name, JsonName = AbpApiProxyScriptingConfiguration.PropertyNameGenerator.Invoke(propertyInfo), Type = ApiTypeNameHelper.GetTypeName(propertyInfo.PropertyType), TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(propertyInfo.PropertyType), IsRequired = customAttributes.OfType <RequiredAttribute>().Any(), Minimum = customAttributes.OfType <RangeAttribute>().Select(x => x.Minimum).FirstOrDefault()?.ToString(), Maximum = customAttributes.OfType <RangeAttribute>().Select(x => x.Maximum).FirstOrDefault()?.ToString(), MinLength = customAttributes.OfType <MinLengthAttribute>().FirstOrDefault()?.Length ?? customAttributes.OfType <StringLengthAttribute>().FirstOrDefault()?.MinimumLength, MaxLength = customAttributes.OfType <MaxLengthAttribute>().FirstOrDefault()?.Length ?? customAttributes.OfType <StringLengthAttribute>().FirstOrDefault()?.MaximumLength, Regex = customAttributes.OfType <RegularExpressionAttribute>().Select(x => x.Pattern).FirstOrDefault() }); }
public void GetSimpleTypeName_Test() { ApiTypeNameHelper.GetSimpleTypeName(typeof(CycleClass)).ShouldBe(TypeHelper.GetSimplifiedName(typeof(CycleClass))); ApiTypeNameHelper.GetSimpleTypeName(typeof(CycleClass2)).ShouldBe(TypeHelper.GetSimplifiedName(typeof(CycleClass2))); ApiTypeNameHelper.GetTypeName(typeof(CycleClass3)).ShouldBe($"[{TypeHelper.GetSimplifiedName(typeof(CycleClass4))}]"); }
public void GetTypeName_Test() { ApiTypeNameHelper.GetTypeName(typeof(CycleClass)).ShouldBe(TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(CycleClass))); ApiTypeNameHelper.GetTypeName(typeof(CycleClass2)).ShouldBe(TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(CycleClass2))); ApiTypeNameHelper.GetTypeName(typeof(CycleClass3)).ShouldBe($"[{TypeHelper.GetFullNameHandlingNullableAndGenerics(typeof(CycleClass4))}]"); }