/// <summary> /// Loads instance source from a dictionary object (provided by JSON) /// </summary> /// <param name="obj">Key/value dictionary with <c>instances</c> and other optional elements</param> /// <exception cref="eduJSON.InvalidParameterTypeException"><paramref name="obj"/> type is not <c>Dictionary<string, object></c></exception> public virtual void Load(object obj) { if (obj is Dictionary <string, object> obj2) { InstanceList.Clear(); // Parse all instances listed. Don't do it in parallel to preserve the sort order. foreach (var el in eduJSON.Parser.GetValue <List <object> >(obj2, "instances")) { var instance = new Instance(); instance.Load(el); InstanceList.Add(instance); } // Parse sequence. Sequence = (uint)eduJSON.Parser.GetValue <int>(obj2, "seq"); // Parse signed date. SignedAt = eduJSON.Parser.GetValue(obj2, "signed_at", out string signed_at) && DateTime.TryParse(signed_at, out var signed_at_date) ? signed_at_date : (DateTime?)null; } else { throw new eduJSON.InvalidParameterTypeException(nameof(obj), typeof(Dictionary <string, object>), obj.GetType()); } }
public void LoadInstances() { InstanceList.Clear(); foreach (Instance inst in Instance.LoadInstances(AppSettings.Main.InstanceDir)) { InstanceList.Add(inst); } }
/// <summary> /// Loads instance source from a dictionary object (provided by JSON) /// </summary> /// <param name="obj">Key/value dictionary with <c>instances</c> and other optional elements</param> /// <exception cref="eduJSON.InvalidParameterTypeException"><paramref name="obj"/> type is not <c>Dictionary<string, object></c></exception> public virtual void Load(object obj) { if (!(obj is Dictionary <string, object> obj2)) { throw new eduJSON.InvalidParameterTypeException(nameof(obj), typeof(Dictionary <string, object>), obj.GetType()); } InstanceList.Clear(); // Parse all instances listed. Don't do it in parallel to preserve the sort order. foreach (var el in eduJSON.Parser.GetValue <List <object> >(obj2, "instances")) { var instance = new Instance(); instance.Load(el); InstanceList.Add(instance); } }
public virtual void SetOriginal(T original) { if (original.Equals(this.original)) { return; } this.original = original; for (int i = 0; i < InstanceList.Count; i++) { Destroy(InstanceList[i].gameObject); } InstanceList.Clear(); ActiveInstanceList.Clear(); deactiveInstanceList.Clear(); }