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

C# – Explicitly compare bool? with true/false to avoid compile-time errors and runtime exceptions

You can’t use nullable bools (bool?) exactly like regular bools, because they aren’t the same thing. When you try to use them like regular bools, you run into compiler errors and runtime exceptions. Fortunately, there is a simple, concise way to treat nullable bools almost-like regular bools. You have to explicitly compare them with true/false. … Read more