1. Guys,

    I'm hopping to create a JSON List with categories and its subs using this:

    Code:
    public class configObj
            {
                public List<configMessages> Messages { set; get; }
                public configObj() { Messages = new List<configMessages>(); }
            }
    public class configMessages
            {
              public string Msg1 = "foo";
              public string Msg2 = "bar";
            }

    Anyone knows how to implement this code?
     
  2. gimme a second mate
    Code:
    public class Info
            {
                public int aa{ set; get; }
                public int bb { set; get; }
                public string ss { set; get; }
                public Info(int i, int r, string n)
                {
                    aa = i;
                    bb = r;
                    ss = n;
                }
            };
            private Dictionary<int, Info> Infoz;public Core.Configuration.DynamicConfigFile InfoData;void Loaded()
            {            InfoData = Interface.GetMod().DataFileSystem.GetDatafile("MyDataFile");
    if (InfoData["Info"] != null)
                    Infoz = JsonConvert.DeserializeObject<Dictionary<int, Info>>((string)JsonConvert.SerializeObject(InfoData["Info"]).ToString());
                else Infoz= new Dictionary<int, Info>();
    }

    and too save it
    Code:
    InfoData["Info"] = Infoz;
                                Interface.GetMod().DataFileSystem.SaveDatafile("MyDataFile");
     
    Last edited by a moderator: Feb 10, 2015
  3. You can use Interface.GetMod().DataFileSystem.
    ReadObject<T>(name) and WriteObject<T>(name, T Object) for custom objects in C# plugins

    For exmp.
    Code:
    try
    {
    List<myclass> myobj = Interface.GetMod().DataFileSystem.ReadObject<List<myclass>>("MyData");
    }
    catch
    {
    List<myclass> myobj = new List<myclass>();
    }
    And to save
    Interface.GetMod().DataFileSystem.WriteObject<List<myclass>>("MyData",myobj);
     
    Last edited by a moderator: Feb 10, 2015
  4. Tnx bros' gonna test.
     
  5. i suggest using my method cause u can simply do

    if(Infoz.ContainsKey((int)player.userID))
    Infoz[(int)player.userID].aa = 2323;
    else
    Infoz.Add((int)target.userID, new Info(42, 2424, "Yay"));

    efficient for loading and saving due to useing steamid as a index dictionary method is pro cause indexing stuff is superior
     
  6. You are basicly serializing and destializing single file for 3 times its time/resource consuming you can still use dictionaries dirrctly with ReadObject
    Dictionary<string,info> = Interface.GetMod().DataFileSystem.ReadObject<Dictionary<string,info>>("MyData"); ofc cast it with try to catch exceptations
     
  7. You can do the same thing with the ReadObject method.
     
  8. @ColonelAngus
    yes but im talking about dictionary compared to list, not the serializing way lol

    @Feramor
    its best to avoid using try and catch methods, you should simply have proper checks in places so you dont cause a exception in the first place

    @Feramor | @ColonelAngus
    thanks for the hint about the serializing im new to oxide but in no way new to c# i have around 10 years experience
     
  9. Only exceptions for ReadObject is File not found and Deserialization error
     
  10. shame we cant use io we could check if file existed
     
  11. You say you have 10 years of experience in c# why not add the functionality to Oxide.
    https://github.com/OxideMod/Oxide
     
  12. im lazy lol
     
  13. This has to be like this Plugin developers should cast it with try structure since we can't construct custom classes with < T > since they may have custom constructers.
     
  14. a simple method in that file to create it with user defined arguments would solve that, without requiring a thrown exception.

    Doesn't have to be like that at all