Configuration for a regex validation.
 /// <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;
 }
Example #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);
        }