Created
March 31, 2011 11:48
-
-
Save Tigraine/896230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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