Just trying an upgrade to V5 beta and have this message on compile:

Error 28 'Xtensive.Orm.Validation.RegexConstraint' does not contain a definition for 'Message'

Is the message parameter going to be added on subsequent releases.

Tony

asked Feb 02 '14 at 09:53

Tony's gravatar image

Tony
53262628


One Answer:

Hello Tony,

this parameter was removed because it didn't provide an easy way for localizing message strings. Since we're evaluating various approaches with new validation framework it might return back in further DO5 updates.

On the other side with new validation you're not limited to bundled property constraints.

For example here is full implementation of NotNullOrEmptyConstraint

/// <summary>
/// Ensures that property value is not 
/// <see langword="null" /> or <see cref="string.Empty"/>.
/// </summary>
public sealed class NotNullOrEmptyConstraint : PropertyValidator
{
  public override void Configure(Domain domain, TypeInfo type, FieldInfo field)
  {
    base.Configure(domain, type, field);

    if (field.ValueType!=typeof (string))
      ThrowConfigurationError(string.Format(Strings.FieldShouldBeOfTypeX, typeof (string).FullName));
  }

  public override ValidationResult Validate(Entity target, object fieldValue)
  {
    var value = (string) fieldValue;
    return !string.IsNullOrEmpty(value) ? Success() : Error(Strings.ValueShouldNotBeEmpty, fieldValue);
  }

  public override IPropertyValidator CreateNew()
  {
    return new NotNullOrEmptyConstraint {
      IsImmediate = IsImmediate,
    };
  }
}

RegexConstraint is slightly longer but approach is generally the same.

answered Feb 03 '14 at 05:58

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×3

Asked: Feb 02 '14 at 09:53

Seen: 1,370 times

Last updated: Feb 03 '14 at 05:58

powered by OSQA