itechnology / T4ResX

Transform ResX files into strongly typed classes via T4
11 stars 4 forks source link

ADD: All resource keys are accessible by ResourceKey constants. #2

Closed dhlavaty closed 1 year ago

dhlavaty commented 11 years ago

All resource keys are accessible by ResourceKey constants. So you can use compiler type checking for validation attributes.

itechnology commented 11 years ago

Cool will have to check this out, i tried getting constants working to be able to use validation attributes (like adding a regex string), but after i got it working i realized it was always getting stuck on the same language.

Will be totally awesome if you actually got that working !

dhlavaty commented 11 years ago

Not really sure what you mean by "getting constants working", but it definitely work for me.

You can use:

[Required(ErrorMessageResourceName = Resources.User.RequiredErrorKey, ErrorMessageResourceType = typeof(Resources.User))]

instead of old version:

[Required(ErrorMessageResourceName = "RequiredError", ErrorMessageResourceType = typeof(Resources.User))]

itechnology commented 11 years ago

ah i see. i was talking about being able to localize some string like

[RegularExpression("pattern")]

unfortunately pattern in this case must either be a inline string or a constant

Found no way to get this working aside creating a custom validation attribute like

[RegularExpressionLocalized("PseudoRegex", ErrorMessageResourceName = "PseudoRegexError", ErrorMessageResourceType = typeof(Resources.Objects.User.Register))]