Specifying assembly in ResourceManager constructor (c#/.net)
I'm trying to create an instance of ResourceManager:
public ResourceManager(baseName, Assembly assembly)
I kn开发者_JS百科ow the name of the assembly that the resource is in (it's not the executingassembly), and it's referenced in the project, but how do I specify it here in the code (using the above constructor)?
May be a bit of a stupid question, but I'm a bit stuck!
Thanks!
The easiest way to grab an assembly reference is via a type that you know is declared in the assembly. e.g.: typeof(SomeKnownType).Assembly
.
You can use the method Assembly.GetAssembly
, perhaps:
Assembly.GetAssembly(typeof(SomeClassInTheAssembly));
...or simply pick up the assembly from a known type:
typeof(SomeClassInTheAssembly).Assembly;
Either way, a Type
from the given assembly is your key.
Assembly asm = Assembly.GetAssembly(typeof(ClassInThatAssembly));
ResourceManager rm = new ResourceManager("resString",asm);
Did you try this?
精彩评论