C# – Deserialize JSON to a dictionary

I’ll show examples of how to deserialize JSON to dictionaries in different scenarios. Deserializing to Dictionary<string, string> When your JSON object has properties with simple string values (as opposed to nested objects), you can deserialize to Dictionary<string, string>. Here’s an example. Consider the following simple JSON object: Note: In all examples, I’ll show the pretty-printed … Read more

C# – Default access modifiers

Classes (and other types) are internal by default. Class members (methods/properties/fields) are private by default. These defaults are applied when you don’t explicitly declare an access modifier. Here’s an example: Since the access modifiers aren’t declared, it uses the defaults. The class is internal while all of the members are private. This is almost never … Read more

ASP.NET Core – Client-side custom validation attributes

I wrote about how to add custom validation attributes. These are used for model validation on the server-side. You can also use these for client-side validation, which I’ll show in this article. 1 – Implement IClientModelValidator The first step is to implement the IClientModelValidator interface in the custom validation attribute class. This has a single … Read more

Implement Interface with auto properties in VS

When you add an interface to a class, you can right-click the class and use the Implement Interface quick action to automatically implement the interface. By default, it implements members that throw exceptions, even the getters and setters: This is fine for methods, but you’d expect it to generate auto properties instead of properties that … Read more