Skip to content

Commit 0296401

Browse files
authored
Merge pull request #6 from LazZiya/metadataProviders
Metadata providers
2 parents b3ce3dd + 4fd5c4a commit 0296401

73 files changed

Lines changed: 1068 additions & 2822 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

XLocalizer/DataAnnotations/Adapters/ExCompareAttributeAdapter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
namespace XLocalizer.DataAnnotations.Adapters
77
{
88
/// <summary>
9-
/// Adapter for providing a localized error message for <see cref="ExCompareAttribute"/>
9+
/// Express validation attributes are deprected. Use default attributes instead. See <a href="https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md">Localizing Data Annotations</a>
1010
/// </summary>
11+
[Obsolete("Express validation attributes are deprected. Use default attributes instead. See https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md")]
1112
public class ExCompareAttributeAdapter : AttributeAdapterBase<ExCompareAttribute>
1213
{
1314
// name of the other attribute

XLocalizer/DataAnnotations/Adapters/ExMaxLengthAttributeAdapter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
namespace XLocalizer.DataAnnotations.Adapters
77
{
88
/// <summary>
9-
/// Adapter for providing a localized error message for <see cref="ExMaxLengthAttribute"/>
9+
/// Express validation attributes are deprected. Use default attributes instead. See <a href="https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md">Localizing Data Annotations</a>
1010
/// </summary>
11+
[Obsolete("Express validation attributes are deprected. Use default attributes instead. See https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md")]
1112
public class ExMaxLengthAttributeAdapter : AttributeAdapterBase<ExMaxLengthAttribute>
1213
{
1314
private int MaxLength { get; set; }

XLocalizer/DataAnnotations/Adapters/ExMinLengthAttributeAdapter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
namespace XLocalizer.DataAnnotations.Adapters
77
{
88
/// <summary>
9-
/// Adapter for providing a localized error message for <see cref="ExMinLengthAttribute"/>
9+
/// Express validation attributes are deprected. Use default attributes instead. See <a href="https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md">Localizing Data Annotations</a>
1010
/// </summary>
11+
[Obsolete("Express validation attributes are deprected. Use default attributes instead. See https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md")]
1112
public class ExMinLengthAttributeAdapter : AttributeAdapterBase<ExMinLengthAttribute>
1213
{
1314
private int MinLength { get; set; }

XLocalizer/DataAnnotations/Adapters/ExRangeAttributeAdapter.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
namespace XLocalizer.DataAnnotations.Adapters
77
{
88
/// <summary>
9-
/// Adapter for providing a localized error message for <see cref="ExRangeAttribute"/>
9+
/// Express validation attributes are deprected. Use default attributes instead. See <a href="https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md">Localizing Data Annotations</a>
1010
/// </summary>
11+
[Obsolete("Express validation attributes are deprected. Use default attributes instead. See https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md")]
1112
public class ExRangeAttributeAdapter : AttributeAdapterBase<ExRangeAttribute>
1213
{
1314
private object Min { get; set; }
@@ -40,7 +41,6 @@ public override void AddValidation(ClientModelValidationContext context)
4041
MergeAttribute(context.Attributes, "data-val-range", GetErrorMessage(context));
4142
MergeAttribute(context.Attributes, "data-val-range-max", $"{Max}");
4243
MergeAttribute(context.Attributes, "data-val-range-min", $"{Min}");
43-
MergeAttribute(context.Attributes, "data-val-required", GetRequiredErrorMessage(context));
4444
}
4545

4646
/// <summary>
@@ -55,15 +55,5 @@ public override string GetErrorMessage(ModelValidationContextBase validationCont
5555

5656
return GetErrorMessage(validationContext.ModelMetadata, validationContext.ModelMetadata.GetDisplayName(), Min, Max);
5757
}
58-
59-
private string GetRequiredErrorMessage(ModelValidationContextBase validationContext)
60-
{
61-
if (validationContext == null)
62-
throw new NullReferenceException(nameof(validationContext));
63-
64-
var msg = Localizer[DataAnnotationsErrorMessages.RequiredAttribute_ValidationError, validationContext.ModelMetadata.GetDisplayName()].Value;
65-
66-
return msg;
67-
}
6858
}
6959
}

XLocalizer/DataAnnotations/Adapters/ExRegularExpressionAttributeAdapter.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
namespace XLocalizer.DataAnnotations.Adapters
77
{
88
/// <summary>
9-
/// Adapter for providing a localized error message for <see cref="ExRegularExpressionAttribute"/>
9+
/// Express validation attributes are deprected. Use default attributes instead. See <a href="https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md">Localizing Data Annotations</a>
1010
/// </summary>
11+
[Obsolete("Express validation attributes are deprected. Use default attributes instead. See https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md")]
1112
public class ExRegularExpressionAttributeAdapter : AttributeAdapterBase<ExRegularExpressionAttribute>
1213
{
1314
private readonly string RegexPattern;
@@ -36,7 +37,6 @@ public override void AddValidation(ClientModelValidationContext context)
3637
MergeAttribute(context.Attributes, "data-val", "true");
3738
MergeAttribute(context.Attributes, "data-val-regex", GetErrorMessage(context));
3839
MergeAttribute(context.Attributes, "data-val-regex-pattern", RegexPattern);
39-
MergeAttribute(context.Attributes, "data-val-required", GetRequiredErrorMessage(context));
4040
}
4141

4242
/// <summary>
@@ -51,15 +51,5 @@ public override string GetErrorMessage(ModelValidationContextBase validationCont
5151

5252
return GetErrorMessage(validationContext.ModelMetadata, validationContext.ModelMetadata.GetDisplayName(), RegexPattern);
5353
}
54-
55-
private string GetRequiredErrorMessage(ModelValidationContextBase validationContext)
56-
{
57-
if (validationContext == null)
58-
throw new NullReferenceException(nameof(validationContext));
59-
60-
var msg = Localizer[DataAnnotationsErrorMessages.RequiredAttribute_ValidationError, validationContext.ModelMetadata.GetDisplayName()].Value;
61-
62-
return msg;
63-
}
6454
}
6555
}

XLocalizer/DataAnnotations/Adapters/ExStringLengthAttributeAdapter.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
namespace XLocalizer.DataAnnotations.Adapters
77
{
88
/// <summary>
9-
/// Adapter for providing a localized error message for <see cref="ExStringLengthAttribute"/>
9+
/// Express validation attributes are deprected. Use default attributes instead. See <a href="https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md">Localizing Data Annotations</a>
1010
/// </summary>
11+
[Obsolete("Express validation attributes are deprected. Use default attributes instead. See https://docs.ziyad.info/en/XLocalizer/v1.0/localizing-validation-attributes-errors.md")]
1112
public class ExStringLengthAttributeAdapter : AttributeAdapterBase<ExStringLengthAttribute>
1213
{
1314
private readonly int MaxLenght;
15+
private readonly int MinLength;
1416

1517
/// <summary>
1618
/// Initialize a new instance of <see cref="ExStringLengthAttributeAdapter"/>
@@ -20,6 +22,7 @@ public class ExStringLengthAttributeAdapter : AttributeAdapterBase<ExStringLengt
2022
public ExStringLengthAttributeAdapter(ExStringLengthAttribute attribute, IStringLocalizer stringLocalizer) : base(attribute, stringLocalizer)
2123
{
2224
MaxLenght = attribute.MaximumLength;
25+
MinLength = attribute.MinimumLength;
2326
}
2427

2528
/// <summary>
@@ -34,6 +37,7 @@ public override void AddValidation(ClientModelValidationContext context)
3437
MergeAttribute(context.Attributes, "data-val", "true");
3538
MergeAttribute(context.Attributes, "data-val-length", GetErrorMessage(context));
3639
MergeAttribute(context.Attributes, "data-val-length-max", $"{MaxLenght}");
40+
MergeAttribute(context.Attributes, "data-val-length-min", $"{MinLength}");
3741
}
3842

3943
/// <summary>
@@ -46,7 +50,7 @@ public override string GetErrorMessage(ModelValidationContextBase validationCont
4650
if (validationContext == null)
4751
throw new NullReferenceException(nameof(validationContext));
4852

49-
return GetErrorMessage(validationContext.ModelMetadata, validationContext.ModelMetadata.GetDisplayName(), MaxLenght);
53+
return GetErrorMessage(validationContext.ModelMetadata, validationContext.ModelMetadata.GetDisplayName(), MaxLenght, MinLength);
5054
}
5155
}
5256
}

0 commit comments

Comments
 (0)