Пример #1
0
        public override object ReadDictionaryKey(ref ObjectContext objectContext, Type keyType)
        {
            var key = objectContext.Reader.Peek <Scalar>();

            OverrideType[] overrideTypes;
            var            keyName = TrimAndParseOverride(key.Value, out overrideTypes);

            key.Value = keyName;

            var keyValue = base.ReadDictionaryKey(ref objectContext, keyType);

            if (overrideTypes[0] != OverrideType.Base)
            {
                YamlAssetMetadata <OverrideType> overrides;
                if (!objectContext.SerializerContext.Properties.TryGetValue(OverrideDictionaryKey, out overrides))
                {
                    overrides = new YamlAssetMetadata <OverrideType>();
                    objectContext.SerializerContext.Properties.Add(OverrideDictionaryKey, overrides);
                }

                var    path = GetCurrentPath(ref objectContext, true);
                ItemId id;
                object actualKey;
                if (YamlAssetPath.IsCollectionWithIdType(objectContext.Descriptor.Type, keyValue, out id, out actualKey))
                {
                    path.PushItemId(id);
                }
                else
                {
                    path.PushIndex(key);
                }
                overrides.Set(path, overrideTypes[0]);
            }

            if (overrideTypes.Length > 1 && overrideTypes[1] != OverrideType.Base)
            {
                ItemId id;
                object actualKey;
                if (YamlAssetPath.IsCollectionWithIdType(objectContext.Descriptor.Type, keyValue, out id, out actualKey))
                {
                    YamlAssetMetadata <OverrideType> overrides;
                    if (!objectContext.SerializerContext.Properties.TryGetValue(OverrideDictionaryKey, out overrides))
                    {
                        overrides = new YamlAssetMetadata <OverrideType>();
                        objectContext.SerializerContext.Properties.Add(OverrideDictionaryKey, overrides);
                    }

                    var path = GetCurrentPath(ref objectContext, true);
                    path.PushIndex(actualKey);
                    overrides.Set(path, overrideTypes[1]);
                }
            }

            return(keyValue);
        }
Пример #2
0
        public override void WriteDictionaryValue(ref ObjectContext objectContext, object key, object value, Type valueType)
        {
            var    path = GetCurrentPath(ref objectContext, true);
            ItemId id;

            if (YamlAssetPath.IsCollectionWithIdType(objectContext.Descriptor.Type, key, out id))
            {
                path.PushItemId(id);
            }
            else
            {
                path.PushIndex(key);
            }
            var itemObjectContext = new ObjectContext(objectContext.SerializerContext, value, objectContext.SerializerContext.FindTypeDescriptor(valueType));

            SetCurrentPath(ref itemObjectContext, path);
            WriteYaml(ref itemObjectContext);
        }
Пример #3
0
        public override object ReadDictionaryValue(ref ObjectContext objectContext, Type valueType, object key)
        {
            var    path = GetCurrentPath(ref objectContext, true);
            ItemId id;

            if (YamlAssetPath.IsCollectionWithIdType(objectContext.Descriptor.Type, key, out id))
            {
                path.PushItemId(id);
            }
            else
            {
                path.PushIndex(key);
            }
            var valueObjectContext = new ObjectContext(objectContext.SerializerContext, null, objectContext.SerializerContext.FindTypeDescriptor(valueType));

            SetCurrentPath(ref valueObjectContext, path);
            return(ReadYaml(ref valueObjectContext));
        }
Пример #4
0
        public override void WriteDictionaryKey(ref ObjectContext objectContext, object key, Type keyType)
        {
            YamlAssetMetadata <OverrideType> overrides;

            if (objectContext.SerializerContext.Properties.TryGetValue(OverrideDictionaryKey, out overrides))
            {
                var           itemPath = GetCurrentPath(ref objectContext, true);
                YamlAssetPath keyPath  = null;
                ItemId        id;
                object        actualKey;
                if (YamlAssetPath.IsCollectionWithIdType(objectContext.Descriptor.Type, key, out id, out actualKey))
                {
                    keyPath = itemPath.Clone();
                    keyPath.PushIndex(actualKey);
                    itemPath.PushItemId(id);
                }
                else
                {
                    itemPath.PushIndex(key);
                }
                var overrideType = overrides.TryGet(itemPath);
                if ((overrideType & OverrideType.New) != 0)
                {
                    objectContext.SerializerContext.Properties.Set(ItemIdSerializerBase.OverrideInfoKey, OverridePostfixes.PostFixNew.ToString());
                }
                if ((overrideType & OverrideType.Sealed) != 0)
                {
                    objectContext.SerializerContext.Properties.Set(ItemIdSerializerBase.OverrideInfoKey, OverridePostfixes.PostFixSealed.ToString());
                }
                if (keyPath != null)
                {
                    overrideType = overrides.TryGet(keyPath);
                    if ((overrideType & OverrideType.New) != 0)
                    {
                        objectContext.SerializerContext.Properties.Set(KeyWithIdSerializer.OverrideKeyInfoKey, OverridePostfixes.PostFixNew.ToString());
                    }
                    if ((overrideType & OverrideType.Sealed) != 0)
                    {
                        objectContext.SerializerContext.Properties.Set(KeyWithIdSerializer.OverrideKeyInfoKey, OverridePostfixes.PostFixSealed.ToString());
                    }
                }
            }
            base.WriteDictionaryKey(ref objectContext, key, keyType);
        }