C# – Using reflection to get properties

You can get a list of a type’s properties using reflection, like this: Note: If you have an object, use movie.GetType().GetProperties() instead. This outputs the following: When you use GetProperties(), it returns a list of PropertyInfo objects. This gives you access the property’s definition (name, type, etc…) and allows you to get and modify its … Read more

System.Text.Json – How to serialize non-public properties

By default, System.Text.Json.JsonSerializer only serializes public properties. If you want to serialize non-public properties, you have two options: In this article, I’ll show examples of both approaches for handling non-public properties. Updated 2022-02-22 to explain the new JsonInclude attribute added in .NET 5. Write a custom JSON converter to serialize non-public properties When the built-in … Read more