473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Abstract classes, static field values and reflection

I've hit the wall with this one:

Using System.Reflection.FieldInfo, I can retrieve the values of any field from an instantiated class and constant fields from abstract classes.
However, it seems impossible to retrieve the values of static fields in an abstract class. Is there any way to do this?

My concrete goal is to retrieve a list containing all static string values in System.Windows.Forms.DataFormats, so I can make a S.W.F.Design.ComponentEditorPage containing a CheckBox for each format used in drag&drop operations.

Any hints are greatly appreciated.
--
Torben K. Jensen
Aug 13 '06 #1
2 2841
Torben K. Jensen wrote:
My concrete goal is to retrieve a list containing all static string
values in System.Windows.Forms.DataFormats, so I can make a
S.W.F.Design.ComponentEditorPage containing a CheckBox for each format
used in drag&drop operations.
I found the solution:
FieldInfo[] info = typeof(DataFormats).GetFields();

foreach (FieldInfo field in info) {
listBox1.Items.Add(field.GetValue(null));
}
I had no idea you could pass a null value to FieldInfo.GetValue() to retrieve the values of static fields, but apparently you can. Whowouldathunk.
--
Torben K. Jensen
Aug 14 '06 #2
"Torben K. Jensen" <de*****@greystork.coma écrit dans le message de news:
0K******************************@speakeasy.net...

| I had no idea you could pass a null value to FieldInfo.GetValue() to
retrieve the values of static fields, but apparently you can.
Whowouldathunk.

Whowouldathunk ? The kind of person who reads the help ? :-))

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Aug 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Daedalus.OS | last post by:
Ok first I'm pretty new to OOP, so my question may sound stupid to some of you. If the only answer you can provide is "get a book about OOP" then don't loose your time and mine cause it's already...
1
by: MIchael McDowell | last post by:
Anyidea how this might be done using and XML Web Service and the XMLSerialzation class? A pointer to an online example would be deeply appreciated. Thankyou in advance, Michael McD
33
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
6
by: Tamir Khason | last post by:
I have some classes that basicly do the same things but different way. There are no default constructors in those classes each constructor should recieve same value So Fooclass:MyBasicClass...
0
by: Ewart MacLucas | last post by:
generated some WMI managed classes using the downloadable extensions for vs2003 from mircrosoft downloads; wrote some test code to enumerate the physicall processors and it works a treat, but a...
2
by: Chicken15 | last post by:
Hi Group. First of all I'm sorry for asking (maybe) such easy questions. But I'm quite stuck now and couldn't come up with a solution by using my C# book or googling. So it would be nice if...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.