Skip to content

Commit

Permalink
The only remaining warnings (all related to lack of XML comments) com…
Browse files Browse the repository at this point in the history
…pletely eradicated. Version up.
  • Loading branch information
jwaliszko committed Nov 8, 2014
1 parent 03d6131 commit dcd4f35
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.2.0")]
[assembly: AssemblyFileVersion("2.2.2.0")]
[assembly: AssemblyVersion("2.2.3.0")]
[assembly: AssemblyFileVersion("2.2.3.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,52 @@ protected ExpressiveValidator(ModelMetadata metadata, ControllerContext context,
}
}

/// <summary>
/// Gets the expression.
/// </summary>
protected string Expression { get; private set; }

/// <summary>
/// Gets the formatted error message.
/// </summary>
protected string FormattedErrorMessage { get; private set; }

/// <summary>
/// Gets names and coarse types of properties extracted from specified expression within given context.
/// </summary>
protected IDictionary<string, string> FieldsMap { get; private set; }

/// <summary>
/// Gets names and values of constants extracted from specified expression within given context.
/// </summary>
protected IDictionary<string, object> ConstsMap { get; private set; }
protected string FieldAttributeType { get; private set; }

protected bool Cached
private string FieldAttributeType { get; set; }

private bool Cached
{
get { return FieldsMap != null || ConstsMap != null; }
}

/// <summary>
/// Provides unique validation type within current annotated field range, when multiple annotations are used (required for client side).
/// </summary>
/// <param name="baseName">Base name.</param>
/// <returns>
/// Unique validation type within current request.
/// </returns>
protected string ProvideUniqueValidationType(string baseName)
{
return string.Format("{0}{1}", baseName, AllocateSuffix());
}

/// <summary>
/// Provides unique suffix related to each attribute instance within current annotated field range
/// (required for multiple annotations to be distingueshed at client side).
/// </summary>
/// <returns>
/// Single lowercase letter from latin alphabet or an empty string.
/// </returns>
private string AllocateSuffix()
{
var count = RequestStorage.Get<int>(FieldAttributeType) + 1;
Assert.AttribsQuantityAllowed(count);

RequestStorage.Set(FieldAttributeType, count);
return count == 1 ? string.Empty : char.ConvertFromUtf32(95 + count);
return count == 1 ? string.Empty : char.ConvertFromUtf32(95 + count); // single lowercase letter from latin alphabet or an empty string
}
}
}
9 changes: 9 additions & 0 deletions src/ExpressiveAnnotations/Attributes/AssertThatAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public AssertThatAttribute(string expression)
{
}

/// <summary>
/// Validates a specified value with respect to the associated validation attribute.
/// Internally used by the <see cref="ExpressiveAttribute.IsValid(object,System.ComponentModel.DataAnnotations.ValidationContext)" /> method.
/// </summary>
/// <param name="value">The value to validate.</param>
/// <param name="validationContext">The validation context.</param>
/// <returns>
/// An instance of the <see cref="T:System.ComponentModel.DataAnnotations.ValidationResult" /> class.
/// </returns>
protected override ValidationResult IsValidInternal(object value, ValidationContext validationContext)
{
if (value != null)
Expand Down
27 changes: 23 additions & 4 deletions src/ExpressiveAnnotations/Attributes/ExpressiveAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@ protected ExpressiveAttribute(string expression, string errorMessage)
CachedValidationFuncs = new Dictionary<Type, Func<object, bool>>();
}

protected Dictionary<Type, Func<object, bool>> CachedValidationFuncs { get; set; }
protected Parser Parser { get; set; }
/// <summary>
/// Gets the cached validation funcs.
/// </summary>
protected Dictionary<Type, Func<object, bool>> CachedValidationFuncs { get; private set; }

/// <summary>
/// Gets the parser.
/// </summary>
protected Parser Parser { get; private set; }

/// <summary>
/// Gets or sets the logical expression based on which specified condition is computed.
/// </summary>
public string Expression { get; set; }

/// <summary>
/// When implemented in a derived class, gets a unique identifier for this <see cref="T:System.Attribute" />.
/// </summary>
public override object TypeId
{
/* From MSDN (msdn.microsoft.com/en-us/library/system.attribute.typeid.aspx, msdn.microsoft.com/en-us/library/6w3a7b50.aspx):
Expand Down Expand Up @@ -91,13 +101,22 @@ public string FormatErrorMessage(string displayName, string expression)
return string.Format(ErrorMessageString, displayName, expression);
}

/// <summary>
/// Validates a specified value with respect to the associated validation attribute.
/// Internally used by the <see cref="ExpressiveAttribute.IsValid(object,System.ComponentModel.DataAnnotations.ValidationContext)" /> method.
/// </summary>
/// <param name="value">The value to validate.</param>
/// <param name="validationContext">The validation context.</param>
/// <returns>
/// An instance of the <see cref="T:System.ComponentModel.DataAnnotations.ValidationResult" /> class.
/// </returns>
protected abstract ValidationResult IsValidInternal(object value, ValidationContext validationContext);

/// <summary>
/// Validates a specified value with respect to the current validation attribute.
/// Validates a specified value with respect to the associated validation attribute.
/// </summary>
/// <param name="value">The value to validate.</param>
/// <param name="validationContext">The context information about the validation operation.</param>
/// <param name="validationContext">The validation context.</param>
/// <returns>
/// An instance of the <see cref="T:System.ComponentModel.DataAnnotations.ValidationResult" /> class.
/// </returns>
Expand Down
9 changes: 9 additions & 0 deletions src/ExpressiveAnnotations/Attributes/RequiredIfAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public RequiredIfAttribute(string expression)
/// </summary>
public bool AllowEmptyStrings { get; set; }

/// <summary>
/// Validates a specified value with respect to the associated validation attribute.
/// Internally used by the <see cref="ExpressiveAttribute.IsValid(object,System.ComponentModel.DataAnnotations.ValidationContext)" /> method.
/// </summary>
/// <param name="value">The value to validate.</param>
/// <param name="validationContext">The validation context.</param>
/// <returns>
/// An instance of the <see cref="T:System.ComponentModel.DataAnnotations.ValidationResult" /> class.
/// </returns>
protected override ValidationResult IsValidInternal(object value, ValidationContext validationContext)
{
var isEmpty = value is string && string.IsNullOrWhiteSpace((string) value);
Expand Down
4 changes: 2 additions & 2 deletions src/ExpressiveAnnotations/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.6.0")]
[assembly: AssemblyFileVersion("2.2.6.0")]
[assembly: AssemblyVersion("2.2.7.0")]
[assembly: AssemblyFileVersion("2.2.7.0")]

0 comments on commit dcd4f35

Please sign in to comment.