c# - Is it possible to create a pseudo resource on the fly without using .resx file using ResourceManager? -
i have resource file strings.resx in project stores default english strings. testing purpose, created 1 more file strings.zh-cn.resx strings stored there not real chinese. test strings have been generated after appending characters strings stored in strings.resx (main resource file). when user logs zh-cn culture, file helps catch hard coded data , untranslated strings. possible can rid of strings.zh-cn.resx file , generate fake resource on fly when current thread culture zh-cn?
basically - there ways can trick resourcemanager return fake strings particular cultures without having physical .resx file?
i using visual studio auto generated designer.cs file fetch resource. can see in designer.cs file there 1 static property each string in .resx file. way resourcemanager initialized in designer.cs under.
/// <summary> /// returns cached resourcemanager instance used class. /// </summary> [global::system.componentmodel.editorbrowsableattribute(global::system.componentmodel.editorbrowsablestate.advanced)] public static global::system.resources.resourcemanager resourcemanager { { if (object.referenceequals(resourceman, null)) { global::system.resources.resourcemanager temp = new global::system.resources.resourcemanager("xxx.xxx.strings", typeof(strings).assembly); resourceman = temp; } return resourceman; } }
this way static property added auto generated code.
/// <summary> /// looks localized string similar absolute. /// </summary> public static string absolute { { return resourcemanager.getstring("absolute", resourceculture); } }
i looking extension points in retrieval. if possible want hook in own custom resourcemanager (or else not sure) , return fake pseudo string when culture zh-cn. main purpose not want generating fake physical resource file testing purpose.
of course can. understand how resourcemanager works? there multiple ways achieve want. couple these:
one option: @ code behind of resource file. tells you need create in instance of resourcemanager
@ stage. 1 way provide name of resource type (aka base name) , assembly in can found. same! make realize need resource type (class) on fly - that: create 1 resource type before create instance of resourcemanager
. type needs have public property name of fake string want retrieve. example how given here: stackoverflow: dynamically create class in c#.
another option: familiarize how mock framework works such moq. can apply same idea faking resource type. rather creating resource type on fly can have resource mock can taught return _fake stri
Comments
Post a Comment