Exemplo n.º 1
0
        public override void WriteDict(IEnumeratedProperty property)
        {
            if (!WriteReferenceAndCheck(property.Value))
            {
                return;
            }

            var type = property.ValueType;

            var keyType = type.GenericTypeArguments.Length > 0 ? type.GenericTypeArguments[0] : typeof(object);
            var valType = type.GenericTypeArguments.Length > 1 ? type.GenericTypeArguments[1] : typeof(object);

            if (property.Value is null)
            {
                return;
            }

            var realType = property.Value.GetType();

            EnsureExpectedType(type, realType);

            if (type != realType)
            {
                WriteTypeInfo(realType);
            }
            else
            {
                WriteTypeInfo(null);
            }

            foreach (var(key, value) in Dict.Iterate(property.Value))
            {
                Writer.Write(true);
                Write(keyType, key);
                Write(valType, value);
            }

            Writer.Write(false);
        }
Exemplo n.º 2
0
        public override void ReadDict(IEnumeratedProperty property)
        {
            if (!ReadReferenceAndCheck(out var reference))
            {
                property.Value = GetReference(reference);
                return;
            }

            var type = property.ValueType;

            var keyType = type.GenericTypeArguments.Length > 0 ? type.GenericTypeArguments[0] : typeof(object);
            var valType = type.GenericTypeArguments.Length > 1 ? type.GenericTypeArguments[1] : typeof(object);

            var realType = ReadTypeInfo() ?? type;

            if (property.Value is not null && !Property.IsDictionaryType(property.Value.GetType()))
            {
                property.Value = null;
            }

            property.Value ??= CreateInstance(realType, type);

            var dict = Dict.Proxy(property.Value);

            dict.Clear();
            // Dict.Clear(dict);

            while (Reader.ReadBoolean())
            {
                object?key = null, value = null;

                Read(keyType, ref key);
                Read(valType, ref value);


                dict[key !] = value;
Exemplo n.º 3
0
 public abstract void ReadList(IEnumeratedProperty property);
Exemplo n.º 4
0
 public abstract void WriteList(IEnumeratedProperty property);