Solved

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

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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