c#: IsNullableType helper class ?
Posted
by mark smith
on Stack Overflow
See other posts from Stack Overflow
or by mark smith
Published on 2010-03-08T11:32:20Z
Indexed on
2010/03/08
11:36 UTC
Read the original article
Hit count: 441
c#
Hi there,
Can anyone help?
I have some code that is shared between 2 projects. The code points to a model which basically is a collection of properties that comes from a db.
Problem being is that some properties use nullable types in 1 model and the other it doesn't
Really the dbs should use the same but they don't ..
so for example there is a property called IsAvailble which uses "bool" in one model and the other it uses bool? (nullable type)
so in my code i do the following
objContract.IsAvailble.Value ? "Yes" : "No" //notice the property .VALUE as its a bool? (nullable type)
but this line will fail on model that uses a standard "bool" (not nullable) as there is no property .VALUE on types that are NOT nullable
Is there some kind of helper class that i check if the property is a nullable type and i can return .Value .. otherwise i just return the property.
Anybody have a solution for this?
© Stack Overflow or respective owner