Configuration for a regex validation.
Exemplo n.º 1
0
 /// <summary>
 /// Deserializes the validation configuration.
 /// </summary>
 /// <param name="configuration">
 /// The serialized validation configuration.
 /// </param>
 /// <param name="context">
 /// The validation configuration deserialization context.
 /// </param>
 /// <returns>
 /// The deserialized configuration.
 /// </returns>
 public object DeserializeConfiguration(string configuration, ValidationContext context)
 {
     var config = new ValidationRegexConfiguration();
     var configData = JsonHelper.Deserialize<JObject>(configuration);
     var dynamicConfig = configData as dynamic;
     var properties = configData.Properties().Select(x => x.Name);
     var propertySet = new HashSet<string>(properties);
     if (propertySet.Contains("regex"))
     {
         config.Pattern = dynamicConfig.regex.Value as string;
     }
     if (propertySet.Contains("message"))
     {
         var message = dynamicConfig.message.Value as string;
         config.Message = ValidationHelper.ReplaceMessageTokens(message, context);
     }
     return config;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Deserializes the validation configuration.
        /// </summary>
        /// <param name="configuration">
        /// The serialized validation configuration.
        /// </param>
        /// <param name="context">
        /// The validation configuration deserialization context.
        /// </param>
        /// <returns>
        /// The deserialized configuration.
        /// </returns>
        public object DeserializeConfiguration(string configuration, ValidationContext context)
        {
            var config        = new ValidationRegexConfiguration();
            var configData    = JsonHelper.Deserialize <JObject>(configuration);
            var dynamicConfig = configData as dynamic;
            var properties    = configData.Properties().Select(x => x.Name);
            var propertySet   = new HashSet <string>(properties);

            if (propertySet.Contains("regex"))
            {
                config.Pattern = dynamicConfig.regex.Value as string;
            }
            if (propertySet.Contains("message"))
            {
                var message = dynamicConfig.message.Value as string;
                config.Message = ValidationHelper.ReplaceMessageTokens(message, context);
            }
            return(config);
        }