07-07-2016 03:37 PM
Basically I have the standard XML configuration file for my app with lots of settings.
I'd like to add Range settings to it but not sure if possible to do it as one element.
Is it possible? I tried this but it didn't work. Thanks!
<MyGraphRange>0,20</MyGraphRange>
// In code
public Range<double> MyGraphRange;
07-08-2016 02:59 PM
By “standard XML configuration file”, I assume you mean the .settings
designer and the .exe.config
runtime configuration file? If so, there appears to be a limitation in the Visual Studio designer with regard to generic types. However, using this answer for nullable types, you can manually edit the .settings
file to use the generic Range<double>
type:
<Setting Name="MyGraphRange" Type="NationalInstruments.Controls.Range<double>" Scope="User">
<Value Profile="(Default)">0,20</Value>
</Setting>
07-11-2016 10:23 AM
Hi Paul, actually I'm using .NET XmlSerializer with standard XML format... I should have mentioned it.
Any way in this case?
Thanks!
07-11-2016 11:13 AM
Testing locally, it does not appear that XmlSerializer
uses the type converter to serialize range values. I am not sure why this is the case, but you can work around it easily enough by exposing the serialized value yourself:
private static readonly TypeConverter _rangeConverter =
new NationalInstruments.Controls.Converters.RangeConverter( );
[XmlIgnore]
public Range<double> MyGraphRange { get; set; }
public string SerializedMyGraphRange {
get { return _rangeConverter.ConvertToInvariantString( MyGraphRange ); }
set { MyGraphRange = (Range<double>)_rangeConverter.ConvertFromInvariantString( value ); }
}