Esempio n. 1
0
        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().ToString();
            }

            obj = Activator.CreateInstance(newType);

            var std = obj as ICfg;

            if (std != null)
            {
                string data;
                if (_perTypeConfig.TryGetValue(taggedTypes.Tag(newType), out data))
                {
                    std.Decode(data);
                }
            }

            StdExtensions.TryCopy_Std_AndOtherData(previous, obj);
        }
Esempio n. 2
0
        public static void TryChangeObjectType(IList list, int index, Type type, TaggedTypesCfg cfg, 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, cfg, ld.keepTypeData);
            }
            else
            {
                el = std.TryDecodeInto <object>(type);
                StdExtensions.TryCopy_Std_AndOtherData(previous, el);
            }

            list[index] = el;
        }