private static void HandleValidationAttribute(RamlType ramlTypeProp, CustomAttributeData attribute)
        {
            switch (attribute.AttributeType.Name)
            {
            case "MaxLengthAttribute":
                ramlTypeProp.Scalar.MaxLength = (int?)attribute.ConstructorArguments.First().Value;
                break;

            case "MinLengthAttribute":
                ramlTypeProp.Scalar.MinLength = (int?)attribute.ConstructorArguments.First().Value;
                break;

            case "RangeAttribute":
                if (!TypeBuilderHelper.IsMinValue(attribute.ConstructorArguments.First()))
                {
                    ramlTypeProp.Scalar.Minimum = ConvertToNullableDecimal(attribute.ConstructorArguments.First().Value);
                }
                if (!TypeBuilderHelper.IsMaxValue(attribute.ConstructorArguments.Last()))
                {
                    ramlTypeProp.Scalar.Maximum = ConvertToNullableDecimal(attribute.ConstructorArguments.Last().Value);
                }
                break;

            case "EmailAddressAttribute":
                ramlTypeProp.Scalar.Pattern = @"pattern: [^\\s@]+@[^\\s@]+\\.[^\\s@]";
                break;

            case "UrlAttribute":
                ramlTypeProp.Scalar.Pattern = @"pattern: ^(ftp|http|https):\/\/[^ \""]+$";
                break;
                //case "RegularExpressionAttribute":
                //    ramlTypeProp.Scalar.Pattern = "pattern: " + attribute.ConstructorArguments.First().Value;
                //    break;
            }
        }
Esempio n. 2
0
        protected string HandleValidationAttribute(CustomAttributeData attribute)
        {
            string res = string.Empty;

            switch (attribute.AttributeType.Name)
            {
            case "MaxLengthAttribute":
                res += ", \"maxLength\": " + attribute.ConstructorArguments.First().Value;
                break;

            case "MinLengthAttribute":
                res += ", \"minLength\": " + attribute.ConstructorArguments.First().Value;
                break;

            case "RangeAttribute":
                if (!TypeBuilderHelper.IsMinValue(attribute.ConstructorArguments.First()))
                {
                    res += ", \"minimum\": " + TypeBuilderHelper.Format(attribute.ConstructorArguments.First());
                }
                if (!TypeBuilderHelper.IsMaxValue(attribute.ConstructorArguments.Last()))
                {
                    res += ", \"maximum\": " + TypeBuilderHelper.Format(attribute.ConstructorArguments.Last());
                }
                break;

            case "EmailAddressAttribute":
                res += @", ""pattern"": ""[^\\s@]+@[^\\s@]+\\.[^\\s@]""";
                break;

            case "UrlAttribute":
                res += @", ""pattern"": ""^(ftp|http|https):\/\/[^ \""]+$""";
                break;
                //case "RegularExpressionAttribute":
                //    res += ", \"pattern\": " + "\"" + attribute.ConstructorArguments.First().Value + "\"";
                //    break;
            }
            return(res);
        }