Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to add Range<double> type to XML config file?

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;

 

0 Kudos
Message 1 of 4
(3,175 Views)

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&lt;double&gt;" Scope="User">
      <Value Profile="(Default)">0,20</Value>
    </Setting>

~ Paul H
0 Kudos
Message 2 of 4
(3,158 Views)

Hi Paul, actually I'm using .NET XmlSerializer with standard XML format... I should have mentioned it.

Any way in this case?

Thanks!

 

0 Kudos
Message 3 of 4
(3,132 Views)

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 ); }
    }

~ Paul H
0 Kudos
Message 4 of 4
(3,129 Views)