Exemplo n.º 1
0
        void ICodedInputStream.ReadEnumArray(uint fieldTag, string fieldName, ICollection <IEnumLite> list,
                                             out ICollection <object> unknown, IEnumLiteMap mapping)
        {
            unknown = null;
            List <object> array = new List <object>();

            if (ReadEnumArray(fieldName, array))
            {
                foreach (object rawValue in array)
                {
                    IEnumLite item = null;
                    if (rawValue is int)
                    {
                        item = mapping.FindValueByNumber((int)rawValue);
                    }
                    else if (rawValue is string)
                    {
                        item = mapping.FindValueByName((string)rawValue);
                    }

                    if (item != null)
                    {
                        list.Add(item);
                    }
                    else
                    {
                        if (unknown == null)
                        {
                            unknown = new List <object>();
                        }
                        unknown.Add(rawValue);
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Reads an enum field value from the stream. The caller is responsible
 /// for converting the numeric value to an actual enum.
 /// </summary>
 public bool ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping)
 {
     tokenizer.Consume(":");
     if (tokenizer.LookingAtInteger())
     {
         int rawValue = tokenizer.ConsumeInt32();
         value = mapping.FindValueByNumber(rawValue);
         if (value != null)
         {
             unknown = null;
             return(true);
         }
         unknown = rawValue;
     }
     else
     {
         string rawName = tokenizer.ConsumeIdentifier();
         value = mapping.FindValueByName(rawName);
         if (value != null)
         {
             unknown = null;
             return(true);
         }
         unknown = rawName;
     }
     return(false);
 }
Exemplo n.º 3
0
 bool ICodedInputStream.ReadEnum(ref IEnumLite value, out object unknown, IEnumLiteMap mapping)
 {
     value   = null;
     unknown = null;
     if (ReadEnum(ref unknown))
     {
         if (unknown is int)
         {
             value = mapping.FindValueByNumber((int)unknown);
         }
         else if (unknown is string)
         {
             value = mapping.FindValueByName((string)unknown);
         }
         return(value != null);
     }
     return(false);
 }
Exemplo n.º 4
0
 public void ReadEnumArray(uint fieldTag, string fieldName, ICollection <IEnumLite> list,
                           out ICollection <object> unknown, IEnumLiteMap mapping)
 {
     unknown = null;
     tokenizer.Consume(":");
     tokenizer.Consume("[");
     while (!tokenizer.TryConsume("]"))
     {
         IEnumLite value;
         if (tokenizer.LookingAtInteger())
         {
             int rawValue = tokenizer.ConsumeInt32();
             value = mapping.FindValueByNumber(rawValue);
             if (value == null)
             {
                 if (unknown == null)
                 {
                     unknown = new List <object>();
                 }
                 unknown.Add(rawValue);
             }
         }
         else
         {
             string rawName = tokenizer.ConsumeIdentifier();
             value = mapping.FindValueByName(rawName);
             if (value == null)
             {
                 if (unknown == null)
                 {
                     unknown = new List <object>();
                 }
                 unknown.Add(rawName);
             }
         }
     }
 }