By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,216 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,216 IT Pros & Developers. It's quick & easy.

What type of object for this?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.