Avatar of Mike Eghtebas
Mike Eghtebas
Flag for United States of America asked on

What variable type or object will be... .net

Please suggest a variable for my use to maintain:

1. key value like "FirstName", "lastName", etc.
2. yes/no for the matching key (boolean or string).
3. index (int is preferred but string is acceptable).
4. Sortable using index data as 1, 2, 3 or "01", "02", "03"

c#

dictionary, arraylist, etc.
Please comment on ease of use and performance.
C#.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
Miguel Oz

8/22/2022 - Mon
SOLUTION
Gustav Brock

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mike Eghtebas

ASKER
Thanks for the help. Would the following format work?

<?xml version="1.0" encoding="utf-8" ?>
<Users>
     <User Name="Default">
         <Settings>
              <Setting SettingName = "Default">
                     <Field Name="First_Name" Text ="All" Include="Yes" Index="2"></Field>
                     <Field Name="Last_Name" Text ="All" Include="Yes" Index="1"></Field>
             </Setting>
        </Settings>
    </User>
    <User Name="John">
         <Settings>
              <Setting SettingName = "Setting-1">
                    <Field Name="First_Name" Text ="John" Include="Yes" Index="1"></Field>
                     <Field Name="Last_Name" Text ="Doe" Include="Yes" Index="2"></Field>
             </Setting>
        </Settings>
    </User>
    <User Name="Robert">
         <Settings>
              <Setting SettingName = "My 1st Setting">
                    <Field Name="First_Name" Text ="Angela" Include="No" Index="2"></Field>
                     <Field Name="Last_Name" Text ="Hansen" Include="Yes" Index="1"></Field>
             </Setting>
        </Settings>
         <Settings>
              <Setting SettingName = "Choice two">
                    <Field Name="First_Name" Text ="Jane" Include="Yes" Index="1"></Field>
                     <Field Name="Last_Name" Text ="Hansen" Include="Yes" Index="2"></Field>
             </Setting>
        </Settings>
    </User>
</Users>

Open in new window

When a new user, say Alex opens the page, the entire block '<User Name="Default"> . . . </User>' will be copied to this xml file as:  <User Name="Alex"> . . . </User>.
Gustav Brock

I can't tell. I've only done it once and that was the other way round - first creating the class, then make it persistent, and from that created the XML file.

/gustav
Miguel Oz

1& 2: First name and last name are not good candidate keys as they are not unique. You are better off using unique integer/string Id depending on list size.
3& 4: Please clarify if we need to sort by First name or last name the whole list. From the xml it seems that sorting will depend on setting???.

if you do not have a unique key you could use a generic list:
LIst<User> users = new LIst<User>();

Open in new window

where User is the user class. My suggestion is to map all information as elements (not attributes) as it is easier to map to a C# class and persist (serialize) later on to xml.
Note: It is possible to serialize C# properties to attributes, but it needs more work as shown here
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Mike Eghtebas

ASKER
1& 2: First name and last name are not good candidate keys
First_Name, Last_Name, etc. are unique per user. And User_First_Name, First_Name, Last_Name_Last_Name, etc. are unique in the entire document.

3& 4: Please clarify if we need to sort by
Only index to be sorted withing User (user will decide how her/his controls has to be displayed, like tab index).
Miguel Oz

In other words, sorting is only needed for how to display first and last name. Correct?

Q1. Any particular reason why you need the settings element?
Xml  (and class) could be simpler if you added directly to User node. For new user you can add a SetupNewUser method to assign the default values.
Q2. Could you explain what include does?
For xml purposes if element is not needed, we do not saved it to xml file.
Mike Eghtebas

ASKER
Hi Miguel,

In other words, sorting is only needed for how to display first and last name. Correct?
Yes. Actually, there will be more than 2, maybe 10 controls.

Q1. Any particular reason why you need the settings element?
settings with username "Default" will be copied to settings with username "User1", "User2", etc. This will allow User1, for example, to modify her/his tab-index to display the controls they way s/he wishes; as you have described in your post above (by using SetupNewUser method).

Xml  (and class) could be simpler if you added directly to User node.
Yes, easy is better. This is good choice.

Q2. Could you explain what include does?
If it is false, that control will be excluded (will not be displayed).  The settings with username "Default" will show all controls meaning all includes will be true by default unless a user decides not to see a control by changing its include to false. We need to saved it to xml file for each user and each control under that user..

Mike
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Miguel Oz

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question