Solved

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

Posted on 2004-09-06
3
3,078 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 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