I would like to instance C#xml and inherit it after inserting or rearranging it in a different form.

Asked 2 years ago, Updated 2 years ago, 107 views

<AppSettings>
  <FileFolder>D:\C#Creations</FileFolder>
  <Sky>User0002</Sky>
  <Users>
    <UserId="User0004">
      <date>10/16/2019</date>
      <Key/>
      <Address>D:\C#Create\Face Mark_Free Material\img048_22.png</Address>
    </User>
    <UserId="User0002">
      <date>10/16/2019</date>
      <Key/>
      <Address>D:\C#Create\Face Mark_Free Material\img038_39.png</Address>
    </User>
    <UserId="User0003">
      <date>10/16/2019</date>
      <Key>3</Key>
      <Address/>
    </User>
  </Users>
</AppSettings>
public class AppSettings
{
    public string FileFolder {get;set;};
    public string SKy {get;set;};
    public List <User>Users {get;set;}
    public class User
    {
        System.Xml.Serialization.XmlAttribute("Id")]
        public string Id {get;set;}
        public string date {get;set;}
        public string key {get;set;}
        public string address {get;set;}
    }

    NonSerialized()
    private static AppSettings_instance;

    [System.Xml.Serialization.XmlIgnore]
    public static AppSettings Instance
    {
        get
        {
            if(_instance==null)
                _instance=new AppSettings();
            return_instance;
        }
        set {_instance=value;}
    }
}

*All tasks such as adding xml will be done in MainForm, and load save will be done at AppSettings.cs where the instance was made.

Sort after last added with Proposition 1 (MainForm) add

varquery=(from x in AppSettings.Instance.Users
                         orderby x.Id
                         select x);

Problem: This sort does not inherit the instance, so I would like to know how to reflect the sort in the instance.

After searching for the Id of the mainform instance, I would like to insert the date, key, and address below the Id before that

I think I should insert it with an index, but how can I get an index of the designated Id?

I'm sorry, but I'd appreciate it if you could help me

Note:
The insertion method was difficult, so I decided to change the Id information and child nodes without erasing them.Therefore, the question itself is no longer necessary, but I would appreciate it if you could give me advice on how to insert it and how to reflect the sort if you need it in the future.
Thank you for your cooperation

c# xml

2022-09-30 21:44

1 Answers

Note this definition.

public List Users {get;set;}
public class User

As for List Users, please do the following instead of defining the list of Class.
public List<User>Users {get;set;}

Also, define the public class user declaration outside of public class AppSettings.

public class AppSettings
{
public string FileFolder {get;set;};
public string SKy {get;set;};
public List <User>Users {get;set;}
}
public class User
{
System.Xml.Serialization.XmlAttribute("Id")]
public string Id {get;set;}
public string date {get;set;}
public string key {get;set;}
public string address {get;set;}
}

Let's try to fix it as above.If there is another problem, please contact me again.


2022-09-30 21:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.