//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)
     });
 }
示例#2
0
    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()
        });
    }
示例#3
0
 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))}]");
 }
示例#4
0
 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))}]");
 }