Property in Nullable type?

Jan 12, 2011 at 12:15 PM

Is it possible to define a property in nullable type?

Statically typed default values are ok but it would be useful if we could get nullable types (bool?) directly from properties.
It seems like it is a must if your default handling logic is dynamic.

Thank you. 

Coordinator
Jun 27, 2011 at 7:15 PM

Interesting idea. I'll take a look.

May 30, 2012 at 11:22 PM
gokhanercan wrote:

Is it possible to define a property in nullable type?

Statically typed default values are ok but it would be useful if we could get nullable types (bool?) directly from properties.
It seems like it is a must if your default handling logic is dynamic.

Thank you. 

I ran into this same limitation. Assume Max is a non-required attribute of type double. At runtime, there's no difference between <element Max="0.0"/> and <element />. Both will return 0.0, but obviously a Max of 0.0 has a very different meaning than not having a Max.

In the auto generated code, you can manually change the type of this property from double to double?, but you'd have to do this any time the code is regenerated. And although I only have two properties in my case, someone with many of these attributes would have to spend quite a bit of time changing the code. It would be great to have support for nullable types out of the box.

Coordinator
May 31, 2012 at 2:24 PM

This is not very hard to do. In the "Configuration Section Explorer" window, right-click the root "Configuration Section Model" node, select "Add New External Type", set its "Name" to "Nullable<global::System.Double>" and its "Namespace" to "System". Replace "System.Double" in the "Name" with whatever type you want nullable.

We do this in our configuration sections at the company I work for, and it works just fine.