Exemplo n.º 1
0
        object ReadConverter(ReadArgs args)
        {
            var s = (string)ReadImpl(AString);

            var converter = args.InstanceType(readRaw)?.Converter;
            if (converter != null)
                return converter.ConvertFromInvariantString(s);

            return new ObjectData(args.TypeData)
            {
                ConverterString = s,
            };
        }
Exemplo n.º 2
0
        object ReadArray(ReadArgs args, ulong oid)
        {
            var ranks = Enumerable.Range(0, args.TypeData.ArrayRank)
                .Select(x => (int)input.ReadVInt())
                .ToArray();

            var eArgs = new ReadArgs(args.TypeData.Element);
            var eType = eArgs.InstanceType(readRaw);
            Array array;
            if (eType != null)
            {
                array = Array.CreateInstance(eType.Type, ranks);
            }
            else
            {
                array = Array.CreateInstance(typeof(ObjectData), ranks);
            }
            Register(oid, array);

            if (ranks.All(x => x > 0))
            {
                var indices = new int[ranks.Length];
                do
                {
                    var value = ReadImpl(eArgs);
                    array.SetValue(value, indices);
                }
                while (Inc());

                bool Inc()
                {
                    for (int i = ranks.Length - 1; i >= 0; i--)
                    {
                        indices[i]++;
                        if (indices[i] < ranks[i])
                            return true;
                        indices[i] = 0;
                    }
                    return false;
                }
            }

            return array;
        }