AdvancedLauncher.UI.Validation.TwitterNameValidation.Validate C# (CSharp) Метод

Validate() публичный Метод

public Validate ( object value, CultureInfo cultureInfo ) : System.Windows.Controls.ValidationResult
value object
cultureInfo System.Globalization.CultureInfo
Результат System.Windows.Controls.ValidationResult
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (string.IsNullOrEmpty(value as string)) {
                return new ValidationResult(false, LanguageManager.Model.Error);
            }
            Regex r = new Regex(@"^[A-Za-z0-9_]{1,15}$");
            while (r.Match(value.ToString()).Success) {
                return new ValidationResult(true, null);
            }
            return new ValidationResult(false, LanguageManager.Model.Error);
        }

Usage Example

 private void ValidateSettings(ProtectedSettings settings)
 {
     if (settings.Proxy == null) {
         settings.Proxy = new ProxySetting();
     }
     ProxySetting proxy = settings.Proxy;
     if (Uri.CheckHostName(proxy.Host) == UriHostNameType.Unknown) {
         proxy.Host = string.Empty;
     }
     if (proxy.Port < 0 || proxy.Port > 65535) {
         proxy.Port = 8080;
     }
     if (settings.Profiles != null) {
         TwitterNameValidation twitterValidator = new TwitterNameValidation();
         GuildNameValidationRule guildNameValidator = new GuildNameValidationRule();
         foreach (var profile in settings.Profiles) {
             if (profile.News == null) {
                 profile.News = new NewsData();
             }
             if (profile.Login == null) {
                 profile.Login = new LoginData();
             }
             if (profile.Rotation == null) {
                 profile.Rotation = new RotationData();
             }
             if (profile.GameModel == null) {
                 profile.GameModel = new GameModel();
             }
             if (!twitterValidator.Validate(profile.News.TwitterUser, null).IsValid) {
                 profile.News.TwitterUser = Utils.GetDefaultTwitter();
             }
             if (profile.Rotation.Guild != null) {
                 if (!guildNameValidator.Validate(profile.Rotation.Guild, null).IsValid) {
                     profile.Rotation.Guild = string.Empty;
                 }
             }
         }
     }
 }
TwitterNameValidation