I want to check with Reflection if a property is nullable string. So my question is similar to this one (Correct way to check if a type is Nullable), except that for a string this does not work since it's not a valueType. Since c# 8 you can make a string property nullable, but i can't seem to distinguish it from a non-nullable property.
#nullable enable
public class User
{
public string? Cid { get; private set; }
public string Zid { get; private set; }
}
User user = new User();
System.Reflection.PropertyInfo property = user.GetType().GetProperty("Cid");
System.Reflection.PropertyInfo property2 = user.GetType().GetProperty("Zid");
Aucun commentaire:
Enregistrer un commentaire