public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jToken = JToken.Load(reader);

            if (jToken.Type == JTokenType.Null)
            {
                return(null);
            }

            int[] values   = ((JArray)jToken).Values <int>().ToArray();
            var   pureType = NullableUtils.GetUnderlyingTypeIfNullable(objectType);

            FieldInfo[] enumFields = pureType.GetFields(BindingFlags.Public | BindingFlags.Static);
            int         setFlags   = 0;

            foreach (FieldInfo enumField in enumFields)
            {
                int enumValue = (int)enumField.GetValue(null);

                // If there is a serialize value set for the enum value, look for that instead of the int value
                SerializeValueAttribute serializeValue = enumField.GetCustomAttribute <SerializeValueAttribute>();
                int searchValue = serializeValue?.Value ?? enumValue;
                if (Array.IndexOf(values, searchValue) >= 0)
                {
                    setFlags |= enumValue;
                }
            }

            return(Enum.ToObject(pureType, setFlags));
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JToken jToken = JToken.Load(reader);

            if (jToken.Type == JTokenType.Null)
            {
                return(null);
            }

            string[] values   = ((JArray)jToken).Values <string>().ToArray();
            var      pureType = NullableUtils.GetUnderlyingTypeIfNullable(objectType);

            FieldInfo[] enumFields = pureType.GetFields(BindingFlags.Public | BindingFlags.Static);
            int         setFlags   = 0;

            foreach (FieldInfo enumField in enumFields)
            {
                // If there is a serialize value set for the enum value, look for the instead of the int value
                SerializeValueAttribute serializeValue = enumField.GetCustomAttribute <SerializeValueAttribute>();
                string searchValue = serializeValue?.Value ?? enumField.Name;
                if (serializer.ContractResolver is CamelCasePropertyNamesContractResolver)
                {
                    searchValue = char.ToLowerInvariant(searchValue[0]) + searchValue.Substring(1);
                }

                // If the value is in the json array, or the int value into the flags
                if (Array.IndexOf(values, searchValue) >= 0)
                {
                    setFlags |= (int)enumField.GetValue(null);
                }
            }

            return(Enum.ToObject(pureType, setFlags));
        }