internal static CustomizedModel DeserializeCustomizedModel(JsonElement element) { int? propertyRenamedAndTypeChanged = default; CustomFruitEnum fruit = default; CustomDaysOfWeek daysOfWeek = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("ModelProperty")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } propertyRenamedAndTypeChanged = property.Value.GetInt32(); continue; } if (property.NameEquals("Fruit")) { fruit = property.Value.GetString().ToCustomFruitEnum(); continue; } if (property.NameEquals("DaysOfWeek")) { daysOfWeek = new CustomDaysOfWeek(property.Value.GetString()); continue; } } return(new CustomizedModel(propertyRenamedAndTypeChanged, fruit, daysOfWeek)); }
static void Main(string[] args) { //get actual current day of week DayOfWeek currentDayOfWeek = new DayOfWeek(); currentDayOfWeek = System.DateTime.Today.DayOfWeek; //get user input string userInput = Console.ReadLine(); //parse user input to enum value CustomDaysOfWeek day = (CustomDaysOfWeek)Enum.Parse(typeof(CustomDaysOfWeek), userInput); if (day == CustomDaysOfWeek.wednesday) { Console.WriteLine("You are correct, today is " + userInput); } else { Console.WriteLine("Today is not " + userInput); } Console.Read(); }
internal static SecondModel DeserializeSecondModel(JsonElement element) { int stringProperty = default; IReadOnlyDictionary <string, string> dictionaryProperty = default; CustomDaysOfWeek?daysOfWeek = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("StringProperty")) { stringProperty = property.Value.GetInt32(); continue; } if (property.NameEquals("DictionaryProperty")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { if (property0.Value.ValueKind == JsonValueKind.Null) { dictionary.Add(property0.Name, null); } else { dictionary.Add(property0.Name, property0.Value.GetString()); } } dictionaryProperty = dictionary; continue; } if (property.NameEquals("DaysOfWeek")) { if (property.Value.ValueKind == JsonValueKind.Null) { continue; } daysOfWeek = new CustomDaysOfWeek(property.Value.GetString()); continue; } } return(new SecondModel(stringProperty, dictionaryProperty, daysOfWeek)); }
internal static RenamedModelStruct DeserializeRenamedModelStruct(JsonElement element) { string modelProperty = default; CustomFruitEnum? fruit = default; CustomDaysOfWeek?daysOfWeek = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("ModelProperty")) { foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("ModelProperty")) { if (property0.Value.ValueKind == JsonValueKind.Null) { continue; } modelProperty = property0.Value.GetString(); continue; } if (property0.NameEquals("Fruit")) { if (property0.Value.ValueKind == JsonValueKind.Null) { continue; } fruit = property0.Value.GetString().ToCustomFruitEnum(); continue; } if (property0.NameEquals("DaysOfWeek")) { if (property0.Value.ValueKind == JsonValueKind.Null) { continue; } daysOfWeek = new CustomDaysOfWeek(property0.Value.GetString()); continue; } } continue; } } return(new RenamedModelStruct(modelProperty, fruit, daysOfWeek)); }
internal CustomizedModel(int?propertyRenamedAndTypeChanged, CustomFruitEnum customizedFancyField, CustomDaysOfWeek daysOfWeek) { PropertyRenamedAndTypeChanged = propertyRenamedAndTypeChanged; CustomizedFancyField = customizedFancyField; DaysOfWeek = daysOfWeek; }