Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now