Skip to content

Commit f41770a

Browse files
authored
samples: ⬆️ UnitsNet 4.7.0 to 5.0.9 (#1231)
Main breaking change was the removal of `QuantityType` enum, replaced with quantity names instead.
1 parent 1f7c3eb commit f41770a

File tree

10 files changed

+29
-31
lines changed

10 files changed

+29
-31
lines changed

Samples/MvvmSample.Wpf/MvvmSample.Wpf/Converters/UnitToStringConverter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
3636

3737
IQuantity quantityInUnit = quantity.ToUnit(unitEnumValue);
3838

39-
return quantityInUnit.ToString(null, significantDigits);
40-
39+
return quantityInUnit.ToString($"s{significantDigits}", null);
4140
}
4241

4342
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

Samples/MvvmSample.Wpf/MvvmSample.Wpf/MvvmSample.Wpf.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
<Reference Include="System.Xaml">
8383
<RequiredTargetFramework>4.0</RequiredTargetFramework>
8484
</Reference>
85-
<Reference Include="UnitsNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=f8601875a1f041da, processorArchitecture=MSIL">
86-
<HintPath>..\..\packages\UnitsNet.4.7.0\lib\net40\UnitsNet.dll</HintPath>
85+
<Reference Include="UnitsNet, Version=5.0.0.0, Culture=neutral, PublicKeyToken=f8601875a1f041da, processorArchitecture=MSIL">
86+
<HintPath>..\..\packages\UnitsNet.5.9.0\lib\netstandard2.0\UnitsNet.dll</HintPath>
8787
</Reference>
8888
<Reference Include="Unity.Abstractions, Version=3.3.1.0, Culture=neutral, PublicKeyToken=6d32ff45e0ccc69f, processorArchitecture=MSIL">
8989
<HintPath>..\..\packages\Unity.Abstractions.3.3.1\lib\net47\Unity.Abstractions.dll</HintPath>

Samples/MvvmSample.Wpf/MvvmSample.Wpf/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<package id="System.Security.Permissions" version="4.5.0" targetFramework="net471" />
1111
<package id="System.Security.Principal.Windows" version="4.5.1" targetFramework="net471" />
1212
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
13-
<package id="UnitsNet" version="4.7.0" targetFramework="net471" />
13+
<package id="UnitsNet" version="5.9.0" targetFramework="net48" />
1414
<package id="Unity" version="5.8.11" targetFramework="net471" />
1515
<package id="Unity.Abstractions" version="3.3.1" targetFramework="net471" />
1616
<package id="Unity.Container" version="5.8.11" targetFramework="net471" />

Samples/UnitConverter.Console/UnitConverter.Console.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="UnitsNet" Version="5.0.0-alpha001" />
11+
<PackageReference Include="UnitsNet" Version="5.9.0" />
1212
</ItemGroup>
1313

1414
</Project>

Samples/UnitConverter.Wpf/UnitConverter.Wpf/IMainWindowVm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace UnitsNet.Samples.UnitConverter.Wpf
1111
/// </summary>
1212
public interface IMainWindowVm : INotifyPropertyChanged
1313
{
14-
ReadOnlyObservableCollection<QuantityType> Quantities { get; }
14+
ReadOnlyObservableCollection<string> Quantities { get; }
1515
ReadOnlyObservableCollection<UnitListItem> Units { get; }
16-
QuantityType SelectedQuantity { get; set; }
16+
string SelectedQuantity { get; set; }
1717

1818
[CanBeNull]
1919
UnitListItem SelectedFromUnit { get; set; }

Samples/UnitConverter.Wpf/UnitConverter.Wpf/MainWindow.xaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@
2323
</Grid.RowDefinitions>
2424

2525
<GroupBox Header="Quantity" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" Grid.RowSpan="2">
26-
<ListBox
27-
ItemsSource="{Binding Path=Quantities}"
26+
<ListBox
27+
ItemsSource="{Binding Path=Quantities}"
2828
SelectedItem="{Binding SelectedQuantity, Mode=TwoWay}"
2929
SelectionChanged="Selector_OnSelectionChanged" />
3030
</GroupBox>
3131

3232
<GroupBox Header="From" Grid.Row="0" Grid.Column="1">
3333
<Grid>
34-
<ListBox
35-
ItemsSource="{Binding Path=Units}"
34+
<ListBox
35+
ItemsSource="{Binding Path=Units}"
3636
DisplayMemberPath="Text"
3737
SelectedItem="{Binding SelectedFromUnit, Mode=TwoWay}" />
3838
</Grid>
3939
</GroupBox>
4040

4141
<GroupBox Header="To" Grid.Row="0" Grid.Column="3">
4242
<Grid>
43-
<ListBox
44-
ItemsSource="{Binding Path=Units}"
43+
<ListBox
44+
ItemsSource="{Binding Path=Units}"
4545
DisplayMemberPath="Text"
4646
SelectedItem="{Binding SelectedToUnit, Mode=TwoWay}" />
4747
</Grid>
4848
</GroupBox>
4949

50-
50+
5151
<WrapPanel Grid.Row="1" Grid.Column="0" Margin="10">
5252
<!--Placeholder-->
5353
</WrapPanel>

Samples/UnitConverter.Wpf/UnitConverter.Wpf/MainWindowDesignVM.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.ObjectModel;
33
using System.ComponentModel;
44
using System.Linq;
5-
using System.Runtime.CompilerServices;
65
using System.Windows.Input;
76

87
namespace UnitsNet.Samples.UnitConverter.Wpf
@@ -15,17 +14,17 @@ public sealed class MainWindowDesignVm : IMainWindowVm
1514
{
1615
public MainWindowDesignVm()
1716
{
18-
Quantities = ToReadOnly(Quantity.Types);
17+
Quantities = ToReadOnly(Quantity.Infos.Select(i => i.Name));
1918
Units = ToReadOnly(Length.Units.Select(u => new UnitListItem(u)));
20-
SelectedQuantity = QuantityType.Length;
19+
SelectedQuantity = Length.Info.Name;
2120
SelectedFromUnit = Units[1];
2221
SelectedToUnit = Units[2];
2322
}
2423

2524

26-
public ReadOnlyObservableCollection<QuantityType> Quantities { get; }
25+
public ReadOnlyObservableCollection<string> Quantities { get; }
2726
public ReadOnlyObservableCollection<UnitListItem> Units { get; }
28-
public QuantityType SelectedQuantity { get; set; }
27+
public string SelectedQuantity { get; set; }
2928
public UnitListItem SelectedFromUnit { get; set; }
3029
public UnitListItem SelectedToUnit { get; set; }
3130

Samples/UnitConverter.Wpf/UnitConverter.Wpf/MainWindowVM.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public sealed class MainWindowVm : IMainWindowVm
2121

2222
[CanBeNull] private UnitListItem _selectedFromUnit;
2323

24-
private QuantityType _selectedQuantity;
24+
private string _selectedQuantity;
2525

2626
[CanBeNull] private UnitListItem _selectedToUnit;
2727

2828
private decimal _toValue;
2929

3030
public MainWindowVm()
3131
{
32-
Quantities = ToReadOnly(Quantity.Types);
32+
Quantities = ToReadOnly(Quantity.Infos.Select(i => i.Name));
3333

3434
_units = new ObservableCollection<UnitListItem>();
3535
Units = new ReadOnlyObservableCollection<UnitListItem>(_units);
@@ -38,15 +38,15 @@ public MainWindowVm()
3838
FromValue = 1;
3939
SwapCommand = new DelegateCommand(Swap);
4040

41-
OnSelectedQuantity(QuantityType.Length);
41+
OnSelectedQuantity(Length.Info.Name);
4242
}
4343

4444
public ICommand SwapCommand { get; }
4545

46-
public ReadOnlyObservableCollection<QuantityType> Quantities { get; }
46+
public ReadOnlyObservableCollection<string> Quantities { get; }
4747
public ReadOnlyObservableCollection<UnitListItem> Units { get; }
4848

49-
public QuantityType SelectedQuantity
49+
public string SelectedQuantity
5050
{
5151
get => _selectedQuantity;
5252
set
@@ -138,12 +138,12 @@ private void UpdateResult()
138138
ToValue = Convert.ToDecimal(convertedValue);
139139
}
140140

141-
private void OnSelectedQuantity(QuantityType quantityType)
141+
private void OnSelectedQuantity(string quantityName)
142142
{
143-
QuantityInfo quantityInfo = Quantity.GetInfo(quantityType);
143+
QuantityInfo quantityInfo = Quantity.ByName[quantityName];
144144

145145
_units.Clear();
146-
foreach (Enum unitValue in quantityInfo.Units)
146+
foreach (Enum unitValue in quantityInfo.UnitInfos.Select(ui => ui.Value))
147147
{
148148
_units.Add(new UnitListItem(unitValue));
149149
}

Samples/UnitConverter.Wpf/UnitConverter.Wpf/UnitConverter.Wpf.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
<Reference Include="System.Xaml">
6262
<RequiredTargetFramework>4.0</RequiredTargetFramework>
6363
</Reference>
64-
<Reference Include="UnitsNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=f8601875a1f041da, processorArchitecture=MSIL">
65-
<HintPath>..\..\packages\UnitsNet.4.7.0\lib\net40\UnitsNet.dll</HintPath>
64+
<Reference Include="UnitsNet, Version=5.0.0.0, Culture=neutral, PublicKeyToken=f8601875a1f041da, processorArchitecture=MSIL">
65+
<HintPath>..\..\packages\UnitsNet.5.9.0\lib\netstandard2.0\UnitsNet.dll</HintPath>
6666
</Reference>
6767
<Reference Include="WindowsBase" />
6868
<Reference Include="PresentationCore" />

Samples/UnitConverter.Wpf/UnitConverter.Wpf/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
<package id="ControlzEx" version="3.0.2.4" targetFramework="net471" />
44
<package id="MahApps.Metro" version="1.6.5" targetFramework="net471" />
55
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
6-
<package id="UnitsNet" version="4.7.0" targetFramework="net471" />
6+
<package id="UnitsNet" version="5.9.0" targetFramework="net48" />
77
</packages>

0 commit comments

Comments
 (0)