Example #1
0
        /// <summary>
        /// Converts Any Json Array to a List of Enums
        /// </summary>
        public static List <T> JsonArrayToEnumList <T>(this JsonArray jsonArray, EnumSerialization enumSerialization)
        {
            int      size     = jsonArray.Count;
            List <T> enumList = new List <T>(size);

            for (int i = 0; i < size; ++i)
            {
                enumList.Add(enumSerialization.StringToEnum <T>(jsonArray[i].AsString));
            }

            return(enumList);
        }
        /// <summary>
        /// Sets the list to a deserialized JsonArray
        /// </summary>
        /// <param name="array"></param>
        /// <param name="serialization"></param>
        private void Deserialize(JsonArray array, EnumSerialization serialization)
        {
            List <TEnum> list = array.JsonArrayToEnumList <TEnum>(serialization);
            List <int>   temp = new List <int>();

            for (int i = 0; i < list.Count; ++i)
            {
                temp.Add((int)Convert.ChangeType(list[i], typeof(int)));
            }

            this.list = temp;
        }
 public static List <EnumListContainer <T> > JsonArrayToEnumListContainerList <T>(this JsonArray arr, EnumSerialization serialization)
 {
     return(arr.JsonArrayToList((JsonValue val) =>
     {
         return new EnumListContainer <T>(val, serialization);
     }));
 }
 /// <summary>
 /// Constructor from a JsonArray of EnumStrings
 /// </summary>
 /// <param name="json"></param>
 /// <param name="serialization"></param>
 public EnumListContainer(JsonArray json, EnumSerialization serialization)
 {
     Deserialize(json, serialization);
 }