Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class MultiResourceWrapper : DynamicObject
{
private readonly Dictionary<string, object> resources = new Dictionary<string, object>();
public MultiResourceWrapper()
{
var assemblyNamespace = this.GetType().Assembly.GetManifestResourceNames();
foreach (var s in assemblyNamespace)
{
var manager = new ResourceManager(ExtractResourceFullName(s), GetType().Assembly);
var name = ExtractResourceName(s);
resources.Add(name, new ResourceWrapper(manager));
}
}
string ExtractResourceFullName(string s)
{
var regex = new Regex(@"(.*).resources$");
return regex.Match(s).Groups[1].Value;
}
string ExtractResourceName(string s)
{
var regex = new Regex(@"([a|A-z|Z]*).resources$");
return regex.Match(s).Groups[1].Value;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = resources[binder.Name];
return true;
}
public class ResourceWrapper : DynamicObject
{
readonly ResourceManager manager;
public ResourceWrapper(ResourceManager manager)
{
this.manager = manager;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = manager.GetString(binder.Name);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.