Solved

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

Posted on 2004-09-06
3
3,091 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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