In order to check if a Type ( propertyType ) is nullable, I’m using:
bool isNullable = "Nullable`1".Equals(propertyType.Name)
Is there some way that avoid using magic strings ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Absolutely – use
Nullable.GetUnderlyingType:Note that this uses the non-generic static class
System.Nullablerather than the generic structNullable<T>.Also note that that will check whether it represents a specific (closed) nullable value type… it won’t work if you use it on a generic type, e.g.