public static List <T> Decode_List <T>(this string data, out List <T> l, ref ListMetaData ld, TaggedTypesCfg tps) where T : IGotClassTag { l = new List <T>(); if (ld == null) { ld = new ListMetaData(); } var overCody = new CfgDecoder(data); foreach (var tag in overCody) { switch (tag) { case CfgEncoder.ListMetaTag: ld.Decode(overCody.GetData()); break; case CfgEncoder.ListTag: var cody = new CfgDecoder(overCody.GetData()); foreach (var t in cody) { l.Add(cody.DecodeData <T>(tps, ld)); } break; default: l.Add(overCody.DecodeData <T>(tps, ld)); break; } } return(l); }
public CfgEncoder Add <T>(string tag, List <T> lst, ListMetaData ld) where T : ICfg { var cody = new CfgEncoder(); if (lst != null) { var indTypes = typeof(T).TryGetDerivedClasses(); if (indTypes != null) { for (var i = 0; i < lst.Count; i++) { var v = lst[i]; cody.Add(v, indTypes, ld, i); } } else { foreach (var v in lst) { if (v != null) { cody.Add(CfgDecoder.ListElementTag, v); } else { cody.Add_String(NullTag, ""); } } } } return(Add(tag, new CfgEncoder().Add(ListMetaTag, ld).Add(ListTag, cody))); }
public CfgEncoder Add_Abstract <T>(string tag, List <T> val, ListMetaData ld) where T : IGotClassTag { var cody = new CfgEncoder(); if (val != null) { if (ld == null) { foreach (var v in val) { cody.Add(v.ClassTag, v); } } else { for (var i = 0; i < val.Count; i++) { var v = val[i]; cody.Add_Abstract(v, ld, i); } } } Add(tag, new CfgEncoder().Add(ListMetaTag, ld).Add(ListTag, cody)); return(this); }
public static List <T> Decode_List_Derived <T>(this string data, out List <T> l, ref ListMetaData ld) where T : ICfg { if (ld == null) { ld = new ListMetaData(); } l = new List <T>(); var tps = typeof(T).TryGetDerivedClasses(); var overCody = new CfgDecoder(data); foreach (var tag in overCody) { switch (tag) { case CfgEncoder.ListMetaTag: ld.Decode(overCody.GetData()); break; case CfgEncoder.ListTag: var cody = new CfgDecoder(overCody.GetData()); if (tps != null) { foreach (var t in cody) { l.Add(cody.DecodeData <T>(tps, ld)); } } break; default: l.Add(overCody.DecodeData <T>(tps, ld)); break; } } return(l); }
private CfgEncoder Add <T>(T val, IList <Type> types, ListMetaData ld, int index) where T : ICfg { var el = ld.elementDatas.GetIfExists(index); if (!QcUnity.IsNullOrDestroyed_Obj(val)) { var typeIndex = types.IndexOf(val.GetType()); if (typeIndex != -1) { el?.SetRecognized(); Add(typeIndex.ToString(), val.Encode()); } else { el = ld.elementDatas[index]; el.unrecognized = true; el.stdDta = val.Encode().ToString(); Add_String(UnrecognizedTag, " "); } } else { if (el != null && el.unrecognized) { Add_String(el.unrecognizedUnderTag, el.stdDta); } else { Add_String(NullTag, ""); } } return(this); }
private CfgEncoder Add_Abstract <T>(T val, ListMetaData ld, int index) where T : IGotClassTag { var el = ld.elementDatas.GetIfExists(index); if (val == null) { return((el != null && el.unrecognized) ? Add_String(el.unrecognizedUnderTag, el.stdDta) : Add_String(NullTag, "")); } el?.SetRecognized(); return(Add(val.ClassTag, val)); }
public static List <T> TryDecode_IntoList_Elements <T>(this string data, List <T> l, ref ListMetaData ld) where T : ICfg, new() { if (ld == null) { ld = new ListMetaData(); } var overCody = new CfgDecoder(data); var index = 0; foreach (var tag in overCody) { switch (tag) { case CfgEncoder.ListMetaTag: ld.Decode(overCody.GetData()); break; case CfgEncoder.ListTag: var cody = new CfgDecoder(overCody.GetData()); foreach (var t in cody) { var d = cody.GetData(); if (index >= l.Count || !d.TryDecodeInto(l[index])) { ld.elementDatas[index].Unrecognized(tag, d); } index++; } break; default: var d1 = overCody.GetData(); if (index >= l.Count || !d1.TryDecodeInto(l[index])) { ld.elementDatas[index].Unrecognized(tag, d1); } index++; break; } } return(l); }
private static T Decode <T>(string tag, string data, TaggedTypesCfg tps, ListMetaData ld, int index) where T : IGotClassTag { if (tag == CfgEncoder.NullTag) { return(default(T)); } var type = tps.TaggedTypes.TryGet(tag); if (type != null) { return(data.DecodeInto_Type <T>(type)); } ld.elementDatas[index].Unrecognized(tag, data); return(default(T)); }
private static T Decode <T>(string tag, string data, List <Type> tps, ListMetaData ld, int index) where T : ICfg { if (tag == CfgEncoder.NullTag) { return(default(T)); } var type = tps.TryGet(tag.ToIntFromTextSafe(-1)); if (type != null) { return(data.DecodeInto_Type <T>(type)); } ld.elementDatas[index].Unrecognized(tag, data); return(default(T)); }
public static void TryChangeObjectType(IList list, int index, Type type, ListMetaData ld = null) { var previous = list.TryGetObj(index); var el = previous; var iTag = el as IGotClassTag; var std = (el as ICfg); var ed = ld.TryGetElement(index); if (ed != null && ld.keepTypeData && iTag != null) { ed.ChangeType(ref el, type, iTag.GetTaggedTypes_Safe(), ld.keepTypeData); } else { el = std.TryDecodeInto <object>(type); StdExtensions.TryCopy_Std_AndOtherData(previous, el); } list[index] = el; }
public static List <T> Decode_List <T>(this string data, out List <T> val, ICfgSerializeNestedReferences referencesKeeper, ref ListMetaData ld) where T : ICfg, new() { var prevKeeper = Keeper; Keeper = referencesKeeper; data.Decode_List(out val, ref ld); Keeper = prevKeeper; return(val); }
public CfgEncoder Add_IfNotEmpty <T>(string tag, List <T> lst, ListMetaData ld) where T : ICfg, new() => lst.IsNullOrEmpty() ? this : Add(tag, lst, ld);
public CfgEncoder Add <T>(string tag, List <T> val, ListMetaData ld, TaggedTypesCfg tts) where T : IGotClassTag => Add_Abstract(tag, val, ld);
public static ElementData TryGetElement(this ListMetaData ld, int ind) => ld?.elementDatas.TryGet(ind);
public CfgEncoder Add_IfNotEmpty <T>(string tag, List <T> val, TaggedTypesCfg tts, ListMetaData ld) where T : IGotClassTag => val.IsNullOrEmpty() ? this : Add_Abstract(tag, val, ld);
private static T DecodeData <T>(this CfgDecoder cody, List <Type> tps, ListMetaData ld) where T : ICfg => Decode <T>(cody.currentTag, cody.GetData(), tps, ld, cody.currentTagIndex);
private static T DecodeData <T>(this CfgDecoder cody, TaggedTypesCfg tps, ListMetaData ld) where T : IGotClassTag => Decode <T>(cody.currentTag, cody.GetData(), tps, ld, cody.currentTagIndex);
public static void TryChangeObjectType(IList list, int index, Type type, TaggedTypesCfg cfg, ListMetaData ld = null) { object previous = null; if (list != null && index >= 0 && index < list.Count) { previous = list[index]; } var el = previous; var iTag = el as IGotClassTag; var std = (el as ICfgCustom); var ed = ld.TryGetElement(index); if (ed != null && ld.keepTypeData && iTag != null) { ed.ChangeType(ref el, type, cfg, ld.keepTypeData); } else { el = std.TryDecodeInto <object>(type); CfgExtensions.TryCopy_Std_AndOtherData(previous, el); } list[index] = el; }
public static T TryGet <T>(this List <T> list, ListMetaData meta) => list.TryGet(meta.inspected);
private static T Decode <T>(string tag, string data, TaggedTypesCfg tps, ListMetaData ld, int index) where T : IGotClassTag { if (tag == CfgEncoder.NullTag) { return(default);