public override ClientRequestParameter Compile(object value) { ClientRequestParameter compiled = new ClientRequestParameter() { Name = Name }; string[] options = Regex.Split(Options, "\r\n"); string[] selects; if (IsMultiple) { selects = (string[])value; if (IsRequire && selects.Length < 1) { throw new Exception(string.Format("Поля [{0}] обязательно для заполнения", Name)); } foreach (string select in selects) { if (!options.Contains(select)) { throw new Exception(string.Format("Вариант выбора [{0}] для поля [{1}] не найден", select, Name)); } } compiled.Value = string.Join("; ", selects); } else { if (IsRequire && value == null) { throw new Exception(string.Format("Поле [{0}] обязательно для заполнения", Name)); } string select = (string)value; if (!options.Contains(select)) { throw new Exception(string.Format("Вариант выбора [{0}] для поля [{1}] не найден", select, Name)); } compiled.Value = select; } return compiled; }
public override ClientRequestParameter Compile(object value) { ClientRequestParameter compiled = new ClientRequestParameter() { Name = Name }; string text = (string)value; if (IsRequire && text.Length < 1) { throw new Exception(string.Format("Поле [{0}] обязательно для заполнения", Name)); } if (text.Length < MinLength) { throw new Exception(string.Format("Длина поля [{0}] должна быть не менее {1} символов", Name, MinLength)); } if (text.Length > MaxLength) { throw new Exception(string.Format("Длина поля [{0}] должна быть не более {1} символов", Name, MaxLength)); } compiled.Value = text; return compiled; }