Beispiel #1
0
 /// <summary>
 /// 枚举值解析
 /// </summary>
 /// <param name="xmlDeSerializer">XML 反序列化</param>
 /// <param name="value">目标数据</param>
 /// <param name="index">第一个枚举索引</param>
 /// <param name="nextIndex">第二个枚举索引</param>
 protected static void getIndex(XmlDeSerializer xmlDeSerializer, ref T value, out int index, ref int nextIndex)
 {
     if ((index = enumSearcher.SearchFlagEnum(xmlDeSerializer)) == -1)
     {
         if (xmlDeSerializer.Config.IsMatchEnum)
         {
             xmlDeSerializer.State = DeSerializeState.NoFoundEnumValue;
             return;
         }
         else
         {
             do
             {
                 if (xmlDeSerializer.IsNextFlagEnum() == 0)
                 {
                     return;
                 }
             }while ((index = enumSearcher.SearchFlagEnum(xmlDeSerializer)) == -1);
         }
     }
     do
     {
         if (xmlDeSerializer.IsNextFlagEnum() == 0)
         {
             value = enumValues[index];
             return;
         }
         if ((nextIndex = enumSearcher.SearchFlagEnum(xmlDeSerializer)) != -1)
         {
             break;
         }
     }while (true);
 }
Beispiel #2
0
 /// <summary>
 /// 枚举值解析
 /// </summary>
 /// <param name="xmlDeSerializer">XML 反序列化</param>
 /// <param name="value">目标数据</param>
 internal static void DeSerializeFlags(XmlDeSerializer xmlDeSerializer, ref T value)
 {
     if (!tryDeSerializeNumber(xmlDeSerializer, ref value))
     {
         if (enumSearcher.State == null)
         {
             if (xmlDeSerializer.Config.IsMatchEnum)
             {
                 xmlDeSerializer.State = DeSerializeState.NoFoundEnumValue;
             }
             else
             {
                 xmlDeSerializer.IgnoreSearchValue();
             }
         }
         else
         {
             int index, nextIndex = -1;
             getIndex(xmlDeSerializer, ref value, out index, ref nextIndex);
             if (nextIndex != -1)
             {
                 ulong intValue = enumInts.ULong[index];
                 intValue |= enumInts.ULong[nextIndex];
                 while (xmlDeSerializer.IsNextFlagEnum() != 0)
                 {
                     if ((index = enumSearcher.NextFlagEnum(xmlDeSerializer)) != -1)
                     {
                         intValue |= enumInts.ULong[index];
                     }
                 }
                 value = AutoCSer.Metadata.EnumGenericType <T, ulong> .FromInt(intValue);
             }
         }
     }
 }