Example #1
0
        private TypedArray ReadArray()
        {
            int size = ReadInt32();
            Variant.EnumType elementType = (Variant.EnumType)ReadInt32();

            TypedArray array = new TypedArray(elementType, size);

            ReadDelegate reader = null;
            switch (elementType)
            {
                case VariantBase.EnumType.Float:
                    reader = () => ReadFloat();
                    break;
                case VariantBase.EnumType.Double:
                    reader = () => ReadDouble();
                    break;
                case VariantBase.EnumType.Boolean:
                    reader = () => ReadBoolean();
                    break;
                case VariantBase.EnumType.String:
                    reader = () => ReadString();
                    break;
                case VariantBase.EnumType.Int32:
                    reader = () => ReadInt32();
                    break;
                case VariantBase.EnumType.UInt32:
                    reader = () => ReadUInt32();
                    break;
                case VariantBase.EnumType.Int64:
                    reader = () => ReadInt64();
                    break;
                case VariantBase.EnumType.UInt64:
                    reader = () => ReadUInt64();
                    break;
                case VariantBase.EnumType.Time:
                    reader = () => ReadTime();
                    break;
                case VariantBase.EnumType.DateTime:
                    reader = () => ReadDateTime();
                    break;
                default:
                    throw new VariantException("Case exhaustion: " + array.ElementType);
            }

            for (int i = 0; i < size; ++i)
            {
                array[i] = reader();
            }

            return array;
        }
Example #2
0
 public TypedArray(TypedArray rhs)
 {
     ElementType = rhs.ElementType;
     Value = new Object[rhs.Value.Length];
 }
Example #3
0
        private void Write(TypedArray arg)
        {
            WriteDelegate writer;
            switch (arg.ElementType)
            {
                case VariantBase.EnumType.Float:
                    writer = o => Write((float)o);
                    break;
                case VariantBase.EnumType.Double:
                    writer = o => Write((double)o);
                    break;
                case VariantBase.EnumType.String:
                    writer = o => Write((string)o);
                    break;
                case VariantBase.EnumType.Boolean:
                    writer = o => Write((bool)o);
                    break;
                case VariantBase.EnumType.Int32:
                    writer = o => Write((int)o);
                    break;
                case VariantBase.EnumType.UInt32:
                    writer = o => Write((uint)o);
                    break;
                case VariantBase.EnumType.Int64:
                    writer = o => Write((long)o);
                    break;
                case VariantBase.EnumType.UInt64:
                    writer = o => Write((ulong)o);
                    break;
                case VariantBase.EnumType.Time:
                    writer = o => Write((TimeSpan)o);
                    break;
                case VariantBase.EnumType.DateTime:
                    writer = o => Write((DateTime)o);
                    break;
                default:
                    throw new VariantException("Case exhaustion: " + arg.ElementType);
            }

            Write(arg.Count);
            Write((int)arg.ElementType);

            for (int i = 0; i < arg.Count; ++i)
            {
                writer(arg[i]);
            }
        }