Exemplo n.º 1
0
        public void ToWriter(DataFrames.DataWriter writer, DataFrames.DataKey root, Utils.Logger logger)
        {
            StateDictionary state = new StateDictionary();

            try
            {
                IStreamTypeParser parser = ObjectConverter.FromNode <T>(root, _derivedTypes);

                parser.ToStream(writer, state, logger);
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception ex)
            {
                logger.LogError(CANAPE.Parser.Properties.Resources.GenericStreamParser_WriteException, ex.Message, typeof(T).Name);
                throw;
            }
        }
Exemplo n.º 2
0
        static object GetValue(object target, string name, bool caseSensitive)
        {
            Type baseType;

            if (target is Type)
            {
                baseType = (Type)target;
            }
            else
            {
                baseType = target.GetType();
            }

            PropertyInfo prop = baseType.GetProperty(name, GetFlags(caseSensitive));

            if (prop == null)
            {
                FieldInfo field = baseType.GetField(name, GetFlags(caseSensitive));
                if (field == null)
                {
                    // If a parser type then see if we can pull the value from its state dictionary
                    BaseParser targetParser = target as BaseParser;
                    if (targetParser != null)
                    {
                        StateDictionary dict = targetParser.GetState();
                        if (dict.ContainsKey(name))
                        {
                            return(dict[name]);
                        }
                    }

                    throw new ArgumentException(String.Format(Properties.Resources.ExpressionResolver_CannotFindProperty, name));
                }

                return(field.GetValue(target));
            }
            else
            {
                return(prop.GetValue(target, null));
            }
        }
Exemplo n.º 3
0
        public static void WriteFixedLengthSequenceArray <T>(DataWriter writer, T[] data, StateDictionary state, int length, Logger logger) where T : IStreamTypeParser, new()
        {
            if (length != data.Length)
            {
                Array.Resize(ref data, length);
            }

            foreach (T value in data)
            {
                if (value != null)
                {
                    value.ToStream(writer, state, logger);
                }
                else
                {
                    new T().ToStream(writer, state, logger);
                }
            }
        }
Exemplo n.º 4
0
 public BaseParser(DataReader reader, StateDictionary state, Utils.Logger logger)
 {
     FromStream(reader, state, logger);
 }
Exemplo n.º 5
0
 public void FromStream(DataReader reader, StateDictionary state, Utils.Logger logger)
 {
     Bytes = reader.ReadToEnd();
 }