c# - How to use a custom Resource provider with Attributes? -
how can use custom method retrieve string resources , use on properties? example:
public class friend { [required(errormessage = "invalid name")] [display(name = "friend's name")] public string name { get; set; } }
the default resource provider (if set resourcetype
/errormessageresourcetype
) class public property, resource files doesn't have generated class, plain xml.
i have method resourcehelper.get(key)
returns value expect. how can change use way of retrieving resources?
here few different ways try in case. fourth approach sounds promising.
http://carrarini.blogspot.com/2010/08/localize-aspnet-mvc-2-dataannotations.html
approaches solve problem:
- writing custom build provider, compiles resources database.
- creating dynamic object, transforms property name key resource manager.
- extending attributes of data annotations.
- using t4 template generating class containing resources.
[edit}
- for question regarding dynamic object
in order that, have create friend object dynamically. means inheriting friend dynamicobject class , implementing trygetmember() , trysetmember(). these properties internally works on resource objects "httpcontext.getlocalresourceobject" , let create dynamic friend class localized properties. after that, need implement custom modelbinder use wrap around it.
this guy found better work around that:- mvc3 modelbinder dynamicobject
Comments
Post a Comment