public override object Load(CtpCommandReader reader)
 {
     if (reader.NodeType != CommandSchemaSymbol.Value)
     {
         throw new Exception("Parsing Error");
     }
     return(reader.Value.ToNativeType);
 }
 public override CtpTime Load(CtpCommandReader reader)
 {
     if (reader.NodeType != CommandSchemaSymbol.Value)
     {
         throw new Exception("Parsing Error");
     }
     return((CtpTime)reader.Value);
 }
예제 #3
0
        public void Load(CtpCommandReader reader, out bool isNull, out T1 v1, out T2 v2)
        {
            isNull = reader.IsElementOrArrayNull;
            v1     = default(T1);
            v2     = default(T2);

            if (reader.IsElementOrArrayNull)
            {
                reader.Read();
                return;
            }

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case CommandSchemaSymbol.StartElement:
                case CommandSchemaSymbol.StartArray:
                    if (reader.ElementName == m_item1Name)
                    {
                        v1 = m_serializeT1.Load(reader);
                    }
                    else if (reader.ElementName == m_item2Name)
                    {
                        v2 = m_serializeT2.Load(reader);
                    }
                    else
                    {
                        throw new Exception("Parsing Error");
                    }
                    break;

                case CommandSchemaSymbol.Value:
                    if (reader.ValueName == m_item1Name)
                    {
                        v1 = m_serializeT1.Load(reader);
                    }
                    else if (reader.ValueName == m_item2Name)
                    {
                        v2 = m_serializeT2.Load(reader);
                    }
                    else
                    {
                        throw new Exception("Parsing Error");
                    }
                    break;

                case CommandSchemaSymbol.EndElement:
                    return;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            throw new Exception("Parsing Error");
        }
예제 #4
0
 public override T Load(CtpCommandReader reader)
 {
     if (reader.NodeType != CommandSchemaSymbol.Value)
     {
         throw new Exception("Expecting a value type");
     }
     if (Enum.TryParse(reader.Value.IsString, out T rv))
     {
         return(rv);
     }
     throw new Exception("Invalid Enum Expression");
 }
예제 #5
0
 public override T?Load(CtpCommandReader reader)
 {
     //ToDo: What if the enum is a complex data type.
     if (reader.NodeType != CommandSchemaSymbol.Value)
     {
         throw new Exception("Expecting a value type");
     }
     if (reader.Value.IsNull)
     {
         return(null);
     }
     return(m_serializeT.Load(reader));
 }
        public override KeyValuePair <TKey, TValue> Load(CtpCommandReader reader)
        {
            if (reader.NodeType != CommandSchemaSymbol.StartElement)
            {
                throw new Exception("Expecting An Element Type");
            }
            if (reader.IsElementOrArrayNull)
            {
                throw new Exception("Null is not supported");
            }

            m_serializeT.Load(reader, out bool isNull, out TKey key, out TValue value);
            if (isNull)
            {
                throw new NotSupportedException();
            }

            return(new KeyValuePair <TKey, TValue>(key, value));
        }
        public override TDictionary Load(CtpCommandReader reader)
        {
            if (!reader.IsArray)
            {
                throw new Exception("Expecting An Array Type");
            }
            if (reader.IsElementOrArrayNull)
            {
                reader.Read();

                return(null);
            }

            Dictionary <TKey, TValue> items = new Dictionary <TKey, TValue>(reader.ArrayCount);

            int x = 0;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case CommandSchemaSymbol.StartElement:
                case CommandSchemaSymbol.StartArray:
                case CommandSchemaSymbol.Value:
                    m_serializeT.Load(reader, out bool isNull, out TKey key, out TValue value);
                    if (isNull)
                    {
                        throw new NotSupportedException();
                    }
                    items[key] = value;
                    x++;
                    break;

                case CommandSchemaSymbol.EndArray:
                    return(m_castToType(items));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            throw new ArgumentOutOfRangeException();
        }
        public override TEnum Load(CtpCommandReader reader)
        {
            if (!reader.IsArray)
            {
                throw new Exception("Expecting An Array Type");
            }
            if (reader.IsElementOrArrayNull)
            {
                reader.Read();
                return(null);
            }

            T[] items = new T[reader.ArrayCount];

            int x = 0;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case CommandSchemaSymbol.StartElement:
                case CommandSchemaSymbol.StartArray:
                case CommandSchemaSymbol.Value:
                    items[x] = m_serializeT.Load(reader);
                    x++;
                    break;

                case CommandSchemaSymbol.EndArray:
                    return(m_castToType(items));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            throw new ArgumentOutOfRangeException();
        }
 public abstract T Load(CtpCommandReader reader);
 public override T Load(CtpCommandReader reader)
 {
     return(m_io.Load(reader));
 }
예제 #11
0
 public abstract void Load(object obj, CtpCommandReader reader);
예제 #12
0
            public override void Load(object obj, CtpCommandReader reader)
            {
                T item = m_io.Load(reader);

                m_set(obj, item);
            }
예제 #13
0
        public override T Load(CtpCommandReader reader)
        {
            if (reader.IsElementOrArrayNull)
            {
                if (m_isRootElement)
                {
                    throw new Exception("Root element cannot be null");
                }
                reader.Read();
                return(default(T));
            }

            var rv = m_constructor();

            if (BeforeLoad != null)
            {
                foreach (var item in BeforeLoad)
                {
                    item(rv);
                }
            }
            FieldIO read;
            int     id;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case CommandSchemaSymbol.StartElement:
                case CommandSchemaSymbol.StartArray:
                    if (m_recordsLookup.TryGetValue(reader.ElementName, out id))
                    {
                        read = m_records[id];
                        read.Load(rv, reader);
                    }
                    else
                    {
                        if (MissingElement != null)
                        {
                            foreach (var item in MissingElement)
                            {
                                item(rv, reader.ElementName);
                            }
                        }
                        else
                        {
                            throw new Exception("Missing an element");
                        }
                        reader.SkipElement();
                    }
                    break;

                case CommandSchemaSymbol.Value:
                    if (m_recordsLookup.TryGetValue(reader.ValueName, out id))
                    {
                        read = m_records[id];
                        read.Load(rv, reader);
                    }
                    else
                    {
                        if (MissingValue != null)
                        {
                            foreach (var item in MissingValue)
                            {
                                item(rv, reader.ValueName, reader.Value);
                            }
                        }
                        else
                        {
                            throw new Exception("Missing a value");
                        }
                    }
                    break;

                case CommandSchemaSymbol.EndElement:
                    if (AfterLoad != null)
                    {
                        foreach (var item in AfterLoad)
                        {
                            item(rv);
                        }
                    }
                    return(rv);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            throw new Exception("Error loading.");

            //rv2?.AfterLoad();
            return(rv);
        }