Hi Dan,
Thanks for posting in this group.
Jon has provided you a plain sample to you through reflection.
If your assembly has not been loaded, you should use Assembly.Load static
to load this assembly, then you can use Assembly.GetType("Dummy") to get
"Dummy" type. Then you can follow Jon's code to get the const value.
In the GetValue method, its parameter is the instance object of "Dummy".
Because you want to get the const value(static field) of the class, you
should pass it "null".
Actually, the reflection use the manifest and the metadata to get the
information of the assembly, you can use the ildasm.exe tool followed by
.Net to get the manifest and metadata of an assembly.
I think once you have a clear view of assembly structure, you just need to
look for related classes and methods in System.Reflection namespace in MSDN.
You also can find quick start samples in
www.gotdotnet.com at the link
below:
http://samples.gotdotnet.com/quickstart/howto/
If you still have any question, please feel free to let me know.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: "Dan" <fu***@iol.it>
| Subject: reflection question
| Date: Mon, 3 Nov 2003 11:16:30 +0100
| Lines: 22
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#M**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: ppp-217-133-158-110.cust-adsl.tiscali.it
217.133.158.110
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:196207
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Let's say I have a class like:
|
| class Dummy
| {
| public const string CONE = "one";
| public const string CTWO = "two";
|
| ... other stuff ....
| }
|
| How can I use reflection to get the value of the class constants given a
| string corresponding to the constant name? E.g. starting from the string:
|
| string s = "CONE";
|
| I'd like to retrieve the value of Dummy's constant named CONE (the value
of
| s), i.e. "one". Could anyone give a sample or point me to some useful
| tutorial about reflection?
|
| Thanx!
|
|
|