Solved

Explain what "ResourceManager rm=new ResourceManager("HelloWorldGlobed.myRes",typeof(Form1).Assembly);" means

Posted on 2004-09-06
3
3,072 Views
Last Modified: 2008-02-01
vb.net
private void button1_Click(object sender, System.EventArgs e)
{
ResourceManager rm=new ResourceManager("HelloWorldGlobed.myRes",typeof(Form1).Assembly);
string message=rm.GetString("hello",culture);
MessageBox.Show(message);
}



Hi, im new to .net. i a little bit confuse about this line.
ResourceManager rm=new ResourceManager("HelloWorldGlobed.myRes",typeof(Form1).Assembly);

Particularly "typeof(Form1).Assembly"
can anyone explain to me what that line do? and what that particular parameter mean?
I have a code which is not a form, i not sure what to put inside of typeof().
I guess it's the name of the main class name? im not quite sure.

the code above come from http://www.codeproject.com/csharp/MultiLanguageApplications.asp

 

0
Comment
Question by:Jerry_Pang
  • 2
3 Comments
 
LVL 41

Expert Comment

by:graye
ID: 12002611
Well, let's start at the beginning....

The ResourceManager class is designed to make it easy for your program to support multiple languages (just one of it's functions).  You could write your program in multiple chunks... using a separate "chunk" for all of the text, graphics, etc for a particular language.  That way... to support additional languages, you'd just have to re-do the resource file.  The .Net Framework already knows how to detect the language of the client PC, and use the correct language resources.   Kinda cool...

Consider the ResourceManager as a database... when you want to get something out of the database, you need to write a query...  in this particular case, the query contains a reference to resource "input file" (the HelloWorldGlobal.myRes part), and the name of the assembly where that resource is stored (the "input file" gets compiled into an assembly... so you need to know it's name).  In this case, rather than call the assembly by name, they used a bit of code to generate the assembly name on-the-fly.  

In VB.Net, it'd be more like this:

Dim rm As New ResourceManager("HelloWorldGlobal.myRes",  [Assembly].GetExecutingAssembly())

...need more?
0
 
LVL 9

Author Comment

by:Jerry_Pang
ID: 12012178
,typeof(Form1).Assembly);
this is for? the current running assembly?


i have a follow up question.

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21121213.html
0
 
LVL 41

Accepted Solution

by:
graye earned 125 total points
ID: 12012345
Yes it is...  

However, that's actually rather poor coding style.   The more appropriate "style" for would have been:  Assembly.GetExecutingAssembly()

Let's disect the C# code a wee bit further...

         typeof(Form1).Assembly

Form1 is almost certainly a Windows form class.  The typeof() operator just returns the "system type" of it's argument. So typeof(Form1) would return a system type of "WindowsApplication.Form1".   The Assembly method (tacked on the end) returns the name of the assembly where the Form1 is located.

So, to recap... the code gets the "full name" of the Form1 class and then figures out which assembly that class is compiled into.   As you can see, it's rather a long way around to get to the same thing as "GetExecutingAssembly()".
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question