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 void ChangeType(ref object obj, Type newType, TaggedTypesCfg taggedTypes, bool keepTypeConfig = false) { var previous = obj; var tObj = obj as IGotClassTag; if (keepTypeConfig && tObj != null) { _perTypeConfig[tObj.ClassTag] = tObj.Encode().CfgData; } obj = Activator.CreateInstance(newType); var std = obj as ICfg; if (std != null) { CfgData data; if (_perTypeConfig.TryGetValue(taggedTypes.Tag(newType), out data)) { std.DecodeFull(data); } } CfgExtensions.TryCopy_Std_AndOtherData(previous, obj); }
public virtual bool Inspect() { var changed = pegi.toggleDefaultInspector(this); pegi.nl(); if (inspectedTriggerGroup == -1) { #region Paste Options if ("Paste Options".foldout().nl()) { if (_replaceReceived != null) { var current = TriggerGroup.all.GetIfExists(_replaceReceived.IndexForPEGI); var hint = (current != null) ? "{0} [ Old: {1} => New: {2} triggers ] ".F(_replaceReceived.NameForPEGI, current.Count, _replaceReceived.Count) : _replaceReceived.NameForPEGI; if (hint.enter(ref _inspectReplacementOption)) { _replaceReceived.Nested_Inspect(); } else { if (icon.Done.ClickUnFocus()) { TriggerGroup.all[_replaceReceived.IndexForPEGI] = _replaceReceived; _replaceReceived = null; } if (icon.Close.ClickUnFocus()) { _replaceReceived = null; } } } else { var tmp = ""; if ("Paste Messaged STD data".edit(140, ref tmp) || CfgExtensions.DropStringObject(out tmp)) { var group = new TriggerGroup(); group.DecodeFromExternal(tmp); var current = TriggerGroup.all.GetIfExists(group.IndexForPEGI); if (current == null) { TriggerGroup.all[group.IndexForPEGI] = group; } else { _replaceReceived = group; if (!_replaceReceived.NameForPEGI.SameAs(current.NameForPEGI)) { _replaceReceived.NameForPEGI += " replaces {0}".F(current.NameForPEGI); } } } } pegi.nl(); } #endregion "Trigger Groups".nl(PEGI_Styles.ListLabel); } ExtensionsForGenericCountless.Inspect <UnNullableCfg <TriggerGroup>, TriggerGroup>(TriggerGroup.all, ref inspectedTriggerGroup).changes(ref changed); if (inspectedTriggerGroup == -1) { "At Index: ".edit(60, ref tmpIndex); if (tmpIndex >= 0 && TriggerGroup.all.TryGet(tmpIndex) == null && icon.Add.ClickUnFocus("Create New Group")) { TriggerGroup.all[tmpIndex].NameForPEGI = "Group " + tmpIndex; tmpIndex++; } pegi.nl(); "Adding a group will also try to load it".writeHint(); pegi.nl(); } pegi.nl(); return(changed); }
public bool Inspect() { var changed = false; var newBook = "Books ".edit_List(ref all, ref _inspectedBook, ref changed); if (newBook != null) { newBook.authorName = Shortcuts.users.current.Name; } if (_inspectedBook == -1) { #region Paste Options if (_replaceReceived != null) { if (_replaceReceived.NameForPEGI.enter(ref _inspectReplacementOption)) { _replaceReceived.Nested_Inspect(); } else { if (icon.Done.ClickUnFocus()) { var el = all.GetByIGotName(_replaceReceived); if (el != null) { all[all.IndexOf(el)] = _replaceReceived; } else { all.Add(_replaceReceived); } _replaceReceived = null; } if (icon.Close.ClickUnFocus()) { _replaceReceived = null; } } } else { string tmp = ""; if ("Paste Messaged Book".edit(140, ref tmp) || CfgExtensions.DropStringObject(out tmp)) { var book = new NodeBook(); book.DecodeFromExternal(tmp); if (all.GetByIGotName(book.NameForPEGI) == null) { all.Add(book); } else { _replaceReceived = book; } } } pegi.nl(); #endregion } return(changed); }