473,396 Members | 1,894 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.

What type of object for this?

I need an object similar to a struct that allows me to write something
like this:

public struct TheFields
{
public static string Hand = "Hand";
public static string PersonID = "PersonID";
}

and reference the fields by name such as TheFields.Hand and get the
value "Hand". The above does all of this. However, I need the
ability to loop blindly through these fields (strings) and get their
values. This construct also needs to be passed in as a parameter to
an object, which will then loop through and get the string values.

I don't think an arraylist will work because I can say myarray.Hand.
I'd have to know what the index of hand is and even then, intellisense
will not do myarray[2].Hand. I need the intellisense to popout all of
the fields within this construct so I can go to the one I want.

Any ideas?

Thanks,
Brett

Apr 3 '06 #1
4 1139
Brett,

I would use a class, and then have static fields as you do.

Additionally, I would have a type constructor which would initialize a
read-only dictionary which you expose, which would use reflection and cycle
through the fields exposed on the type. It would populate with name/values,
if you need that.

Either that, or I would pass the type around.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
I need an object similar to a struct that allows me to write something
like this:

public struct TheFields
{
public static string Hand = "Hand";
public static string PersonID = "PersonID";
}

and reference the fields by name such as TheFields.Hand and get the
value "Hand". The above does all of this. However, I need the
ability to loop blindly through these fields (strings) and get their
values. This construct also needs to be passed in as a parameter to
an object, which will then loop through and get the string values.

I don't think an arraylist will work because I can say myarray.Hand.
I'd have to know what the index of hand is and even then, intellisense
will not do myarray[2].Hand. I need the intellisense to popout all of
the fields within this construct so I can go to the one I want.

Any ideas?

Thanks,
Brett

Apr 3 '06 #2
Thanks Nicholas. That's working smoothly.

The next thing is I'd like is to some how black box this. The class
that a developer must create, "TheFields" or something similar, allows
for errors and loose formatting. The parsing class that is accepting
TheFields along with the field list inside of TheFields, is blackboxed
but needs the format/structure outlined above to hold. Since
developers are creating TheFields class, they may decide to start
tweaking their implementation or just get it wrong. If that doesn't
happen, the may copy/paste their code wrong, which causes TheFields
class not to work or an invalid format to be thrown into the parsing
class. Basically, I'd like a factory for TheFields. Since there will
be many unique (unique fields I mean) implementations of TheFields (Ex:
TheFieldsPerson, TheFieldsSupervisor, TheFieldsNewHire, TheFieldsCEO,
etc) with their own restricted field list, I need to avoid these manual
implementations from being scattered everywhere. Any ideas?

Brett

Apr 3 '06 #3
One thing that can be done to abstract some of this implementation is
to have the developer write their new Field class and implement the
static string fields as public. That's simple enough. Then they just
inherit from a class that gathers up their fields and basically does
all of the leg work. They will also need to call the base class
constructor.

Still open on better techinques and thoughts.

Thanks,
Brett

Apr 3 '06 #4
Brett,

I think that you are going about this the wrong way. I think that for
something like this, you should have an attribute which you can set your
values on, which take a key and a value, and then you pass the type to your
methods that are looking to use it (or get the type from somewhere else).

Then, you use reflection to get the attributes which contain the field
info.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brett Romero" <ac*****@cygen.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
Thanks Nicholas. That's working smoothly.

The next thing is I'd like is to some how black box this. The class
that a developer must create, "TheFields" or something similar, allows
for errors and loose formatting. The parsing class that is accepting
TheFields along with the field list inside of TheFields, is blackboxed
but needs the format/structure outlined above to hold. Since
developers are creating TheFields class, they may decide to start
tweaking their implementation or just get it wrong. If that doesn't
happen, the may copy/paste their code wrong, which causes TheFields
class not to work or an invalid format to be thrown into the parsing
class. Basically, I'd like a factory for TheFields. Since there will
be many unique (unique fields I mean) implementations of TheFields (Ex:
TheFieldsPerson, TheFieldsSupervisor, TheFieldsNewHire, TheFieldsCEO,
etc) with their own restricted field list, I need to avoid these manual
implementations from being scattered everywhere. Any ideas?

Brett

Apr 3 '06 #5

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

Similar topics

20
by: Wayne Sutton | last post by:
OK, I'm a newbie... I'm trying to learn Python & have had fun with it so far. But I'm having trouble following the many code examples with the object "self." Can someone explain this usage in...
100
by: E. Robert Tisdale | last post by:
What is an object? Where did this term come from? Does it have any relation to the objects in "object oriented programming"?
3
by: Sathyaish | last post by:
I wanted to practice some Linked List stuff, so I set out to create a linked list. The plan was to create the following: (1) A linked list class in Visual Basic (2) A non-class based linked list...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
86
by: Randy Yates | last post by:
In Harbison and Steele's text (fourth edition, p.111) it is stated, The C language does not specify the range of integers that the integral types will represent, except ot say that type int may...
43
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's...
11
by: Davíð Þórisson | last post by:
hi I'm new to c# and although having read 2 tutorials I cannot find what the parenthesis in these 2 example situations mean; 1) string strKeyValue = (string)sampleConfig; 2) class myParentPage...
5
by: Niu Xiao | last post by:
I saw a lot of codes like: void foo(void* arg) void bar(void** arg) f((void*)p) but what does void pointer mean in c? I just know it stands for generic pointer. thanks.
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
6
by: rn5a | last post by:
The different Page events in the page life cycle like Page_PreInit, Page_Init, Page_Load etc. - are they different stages of the runtime process? Does a server send back the HTML output of an...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.