Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Add localizers to validation attributes #3200

Closed
wants to merge 4 commits into from
Closed

Add localizers to validation attributes #3200

wants to merge 4 commits into from

Conversation

kirthik
Copy link
Contributor

@kirthik kirthik commented Sep 25, 2015

@@ -19,16 +22,26 @@ public class DataAnnotationsClientModelValidatorProvider : IClientModelValidator
{
// A factory for validators based on ValidationAttribute.
internal delegate IClientModelValidator
DataAnnotationsClientModelValidationFactory(ValidationAttribute attribute);
DataAnnotationsClientModelValidationFactory(ValidationAttribute attribute, IStringLocalizer stringLocalizer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be much easier to read if you put the line break after DataAnnotationsClientModelValidationFactory(

@kirthik
Copy link
Contributor Author

kirthik commented Sep 25, 2015

@NTaylorMullen, @rynowak : updated

DataAnnotationsClientModelValidationFactory(ValidationAttribute attribute);
DataAnnotationsClientModelValidationFactory(
ValidationAttribute attribute,
IStringLocalizer stringLocalizer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be much easier to read if you put the line break after DataAnnotationsClientModelValidationFactory(

And now DataAnnotationsClientModelValidationFactory( can move up to the previous line and it looks like normal code!

_stringLocalizerFactory != null)
{
stringLocalizer = _options.Value.DataAnnotationLocalizerProvider(
context.ModelMetadata.ContainerType ?? context.ModelMetadata.ModelType,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: Why do we prefer the ContainerType here as opposed to the model type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primitive data types like string, int are also treated as ModelType. We don't want to create .resx for each data types/property. ContainerType is the Complex type. So we want to look at ModelType only if ContainerType is null

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't have anything to do with what kind of type it is.

Validators are either retrieved for a property or a type. If you're looking at a property, then you'll have a container type.

@NTaylorMullen
Copy link

⌚ Also, are the travis failures due to missing changes from Localization?

@kirthik
Copy link
Contributor Author

kirthik commented Sep 25, 2015

@rynowak, @NTaylorMullen updated


private readonly Dictionary<Type, DataAnnotationsClientModelValidationFactory> _attributeFactories =
BuildAttributeFactoriesDictionary();
private IOptions<MvcDataAnnotationsLocalizationOptions> _options;
private IStringLocalizerFactory _stringLocalizerFactory;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can both be made readonly

@rynowak
Copy link
Member

rynowak commented Sep 25, 2015

:shipit: from me after fixing minor comments

@NTaylorMullen
Copy link

:shipit:

@kirthik
Copy link
Contributor Author

kirthik commented Sep 25, 2015

Thanks @rynowak and @NTaylorMullen. Merged 0889b18

@kirthik kirthik closed this Sep 25, 2015
@dougbu dougbu deleted the fix2766 branch September 21, 2016 21:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants