public static class PropertyInfoExtensions
public static bool CanBeSetToNull(this PropertyInfo property)
if (!property.PropertyType.IsValueType)
if (Nullable.GetUnderlyingType(property.PropertyType) != null)
public string? NullableReferenceType { get; set; }
public string NonNullableReferenceType { get; set; }
public int? NullableValueType { get; set; }
public int NonNullableValueType { get; set; }
var properties = typeof(Example).GetProperties();
foreach (var property in properties)
Console.WriteLine($"Property: {property.Name}, Can be set to null: {property.CanBeSetToNull()}");