private static void ReadAndAssertProperty(JsonReader reader, string propertyName)
 {
     DiscriminatedUnionConverter.ReadAndAssert(reader);
     if (reader.TokenType != JsonToken.PropertyName || !string.Equals(reader.Value.ToString(), propertyName, StringComparison.OrdinalIgnoreCase))
     {
         throw new JsonSerializationException("Expected JSON property '{0}'.".FormatWith(CultureInfo.InvariantCulture, propertyName));
     }
 }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }
            MethodCall <object, object> arg_21_0 = DiscriminatedUnionConverter._getUnionCases;
            object arg_21_1 = null;

            object[] array = new object[2];
            array[0] = objectType;
            IEnumerable enumerable = (IEnumerable)arg_21_0(arg_21_1, array);

            DiscriminatedUnionConverter.ReadAndAssertProperty(reader, "Case");
            DiscriminatedUnionConverter.ReadAndAssert(reader);
            string text = reader.Value.ToString();
            object obj  = null;

            foreach (object current in enumerable)
            {
                if ((string)DiscriminatedUnionConverter._getUnionCaseInfoName(current) == text)
                {
                    obj = current;
                    break;
                }
            }
            if (obj == null)
            {
                throw new JsonSerializationException("No union type found with the name '{0}'.".FormatWith(CultureInfo.InvariantCulture, text));
            }
            DiscriminatedUnionConverter.ReadAndAssertProperty(reader, "Fields");
            DiscriminatedUnionConverter.ReadAndAssert(reader);
            DiscriminatedUnionConverter.ReadAndAssert(reader);
            PropertyInfo[] array2 = (PropertyInfo[])DiscriminatedUnionConverter._getUnionCaseInfoFields(obj, new object[0]);
            List <object>  list   = new List <object>();

            PropertyInfo[] array3 = array2;
            for (int i = 0; i < array3.Length; i++)
            {
                PropertyInfo propertyInfo = array3[i];
                list.Add(serializer.Deserialize(reader, propertyInfo.PropertyType));
                DiscriminatedUnionConverter.ReadAndAssert(reader);
            }
            DiscriminatedUnionConverter.ReadAndAssert(reader);
            MethodCall <object, object> arg_164_0 = DiscriminatedUnionConverter._makeUnion;
            object arg_164_1 = null;

            object[] array4 = new object[3];
            array4[0] = obj;
            array4[1] = list.ToArray();
            return(arg_164_0(arg_164_1, array4));
        }