Skip to content

Commit f3fe0ed

Browse files
committed
Merge from origin/master and solved conflicts
2 parents e26595d + 5044642 commit f3fe0ed

File tree

167 files changed

+28642
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+28642
-99
lines changed

.editorconfig

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# EditorConfig is awesome:http://EditorConfig.org
2+
# Based on: https://raw.githubusercontent.com/dotnet/roslyn/master/.editorconfig
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# Don't use tabs for indentation.
8+
[*]
9+
indent_style = space
10+
trim_trailing_whitespace = true
11+
trim_trailing_white_space_on_save = true
12+
# (Please don't specify an indent_size here; that has too many unintended consequences.)
13+
14+
# Code files
15+
[*.{cs,csx,vb,vbx}]
16+
indent_size = 4
17+
insert_final_newline = true
18+
charset = utf-8-bom
19+
20+
[*.{cmd,bat}]
21+
indent_size = 2
22+
end_of_line = crlf
23+
insert_final_newline = false
24+
25+
[*.{ps1,psm1}]
26+
indent_size = 2
27+
end_of_line = crlf
28+
insert_final_newline = true
29+
charset = utf-8-bom
30+
31+
# Xml project files
32+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
33+
indent_size = 2
34+
35+
# Xml config files
36+
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
37+
indent_size = 2
38+
39+
# JSON files
40+
[*.json]
41+
indent_size = 2
42+
43+
# Dotnet code style settings:
44+
[*.{cs,vb}]
45+
# Sort using and Import directives with System.* appearing first
46+
dotnet_sort_system_directives_first = true
47+
# Avoid "this." and "Me." if not necessary
48+
dotnet_style_qualification_for_field = false:suggestion
49+
dotnet_style_qualification_for_property = false:suggestion
50+
dotnet_style_qualification_for_method = false:suggestion
51+
dotnet_style_qualification_for_event = false:suggestion
52+
53+
# Use language keywords instead of framework type names for type references
54+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
55+
dotnet_style_predefined_type_for_member_access = true:suggestion
56+
57+
# Suggest more modern language features when available
58+
dotnet_style_object_initializer = true:suggestion
59+
dotnet_style_collection_initializer = true:suggestion
60+
dotnet_style_coalesce_expression = true:suggestion
61+
dotnet_style_null_propagation = true:suggestion
62+
dotnet_style_explicit_tuple_names = true:suggestion
63+
64+
# CSharp code style settings:
65+
[*.cs]
66+
# Prefer "var" everywhere
67+
csharp_style_var_for_built_in_types = true:suggestion
68+
csharp_style_var_when_type_is_apparent = true:suggestion
69+
csharp_style_var_elsewhere = true:suggestion
70+
71+
# Prefer method-like constructs to have a block body
72+
csharp_style_expression_bodied_methods = false:none
73+
csharp_style_expression_bodied_constructors = false:none
74+
csharp_style_expression_bodied_operators = false:none
75+
76+
# Prefer property-like constructs to have an expression-body
77+
csharp_style_expression_bodied_properties = true:none
78+
csharp_style_expression_bodied_indexers = true:none
79+
csharp_style_expression_bodied_accessors = true:none
80+
81+
# Suggest more modern language features when available
82+
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
83+
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
84+
csharp_style_inlined_variable_declaration = true:suggestion
85+
csharp_style_throw_expression = true:suggestion
86+
csharp_style_conditional_delegate_call = true:suggestion
87+
88+
# Newline settings
89+
csharp_new_line_before_open_brace = all
90+
csharp_new_line_before_else = true
91+
csharp_new_line_before_catch = true
92+
csharp_new_line_before_finally = true
93+
csharp_new_line_before_members_in_object_initializers = true
94+
csharp_new_line_before_members_in_anonymous_types = true

Build/build-functions.psm1

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
$root = "$PSScriptRoot\.."
1+
$root = "$PSScriptRoot\.."
22
$artifactsDir = "$root\Artifacts"
33
$nugetOutDir = "$root\Artifacts\NuGet"
44
$testReportDir = "$root\Artifacts\Logs"
55
$nuget = "$root\Tools\NuGet.exe"
6+
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
7+
$msbuild = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
8+
if ($msbuild) {
9+
$msbuild = join-path $msbuild 'MSBuild\15.0\Bin\MSBuild.exe'
10+
}
611

712
function Start-NugetRestore {
813
write-host -foreground blue "Restore nugets...`n"
@@ -30,15 +35,22 @@ function Update-GeneratedCode {
3035
write-host -foreground blue "Generate code...END`n"
3136
}
3237

33-
function Start-Build {
38+
function Start-Build([boolean] $skipUWP = $false) {
3439
write-host -foreground blue "Start-Build...`n---"
3540
dotnet build --configuration Release "$root\UnitsNet.sln"
3641
if ($lastexitcode -ne 0) { exit 1 }
3742

38-
# dontnet CLI does not support WindowsRuntimeComponent project type yet
39-
write-host -foreground yellow "WindowsRuntimeComponent project not yet supported by dotnet CLI, using MSBuild15 instead"
40-
& msbuild "$root\UnitsNet.WindowsRuntimeComponent.sln" /verbosity:minimal /p:Configuration=Release
41-
if ($lastexitcode -ne 0) { exit 1 }
43+
if ($skipUWP -eq $true)
44+
{
45+
write-host -foreground yellow "Skipping WindowsRuntimeComponent build by user-specified flag."
46+
}
47+
else
48+
{
49+
# dontnet CLI does not support WindowsRuntimeComponent project type yet
50+
write-host -foreground yellow "WindowsRuntimeComponent project not yet supported by dotnet CLI, using MSBuild15 instead"
51+
& "$msbuild" "$root\UnitsNet.WindowsRuntimeComponent.sln" /verbosity:minimal /p:Configuration=Release
52+
if ($lastexitcode -ne 0) { exit 1 }
53+
}
4254

4355
write-host -foreground blue "Start-Build...END`n"
4456
}

Build/build.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
.SYNOPSIS
33
Build, run tests and pack nugets for all Units.NET projects.
44
.DESCRIPTION
@@ -7,17 +7,21 @@
77
88
Publishing nugets is handled by nuget-publish.bat and run by the build server
99
on the master branch.
10-
11-
Optional strong name signing .pfx key file to produce signed binaries for the signed nugets.
10+
.PARAMETER skipUWP
11+
If flag is set, will skip the UWP (Windows Runtime Component) build step as this requires
12+
some large, extra Visual Studio features to be installed.
1213
.EXAMPLE
13-
powershell ./UpdateAssemblyInfo.ps1 c:\UnitsNet_Key.snk
14+
powershell ./build.ps1
15+
powershell ./build.ps1 -skipUWP
1416
1517
.NOTES
1618
Author: Andreas Gullberg Larsen
17-
Last modified: June 1, 2017
19+
Last modified: Jan 21, 2018
1820
#>
1921
[CmdletBinding()]
20-
Param()
22+
Param(
23+
[switch] $skipUWP
24+
)
2125

2226
remove-module build-functions -ErrorAction SilentlyContinue
2327
import-module $PSScriptRoot\build-functions.psm1
@@ -26,7 +30,7 @@ try {
2630
Remove-ArtifactsDir
2731
Start-NugetRestore
2832
Update-GeneratedCode
29-
Start-Build
33+
Start-Build $skipUWP
3034
Start-Tests
3135
Start-PackNugets
3236
Compress-ArtifactsAsZip

Docs/Images/logo-512.ico

109 KB
Binary file not shown.

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ Stop littering your code with unnecessary calculations, Units.NET gives you all
1212
### Build Targets
1313

1414
* .NET Standard 1.0
15+
* .NET 4.0
1516
* .NET 3.5 Client
1617
* [Windows Runtime Component](https://docs.microsoft.com/en-us/windows/uwp/winrt-components/) for UWP apps (JavaScript, C++ or C#)
1718

1819

1920
### Overview
2021

21-
* [48 quantities with a total of 500+ units](UnitsNet/GeneratedCode/Units) generated from [JSON](UnitsNet/UnitDefinitions/) by [Powershell scripts](UnitsNet/Scripts)
22+
* [50+ quantities with a total of 600+ units](UnitsNet/GeneratedCode/Units) generated from [JSON](UnitsNet/UnitDefinitions/) by [Powershell scripts](UnitsNet/Scripts)
2223
* [1000+ unit tests](https://ci.appveyor.com/project/angularsen/unitsnet) on conversions and localizations
2324
* Immutable structs that implement `Equatable`, `IComparable`
2425
* [Static typing](#static-typing) to avoid ambiguous values or units
2526
* [Operator overloads](#operator-overloads) for arithmetic on quantities
2627
* [Extension methods](#extension-methods) for short-hand creation and conversions
2728
* [Parse and ToString()](#culture) supports cultures and localization
2829
* [Example: Creating a unit converter app](#example-app)
30+
* [Example: WPF app using IValueConverter to parse quantities from input](#example-wpf-app-using-ivalueconverter-to-parse-quantities-from-input)
2931
* [Precision and accuracy](#precision)
3032
* [Serializable with JSON.NET](#serialization)
3133
* Extensible with [custom units](https://github.com/angularsen/UnitsNet/wiki/Extending-with-Custom-Units)
@@ -121,24 +123,48 @@ RotationalSpeedUnit rpm2 == RotationalSpeed.ParseUnit("r/min"); // RotationalSp
121123
string abbrevKg = Mass.GetAbbreviation(MassUnit.Kilogram); // "kg"
122124
```
123125

124-
### <a name="example-app"></a>Example: Creating a unit converter app
126+
### <a name="example-app"></a>Example: Creating a dynamic unit converter app
125127

126-
*TODO: Add actual sample app and link to it here with screenshot. See [#274](https://github.com/angularsen/UnitsNet/issues/274) for details.*
128+
![image](https://user-images.githubusercontent.com/787816/34920961-9b697004-f97b-11e7-9e9a-51ff7142969b.png)
129+
130+
See [Samples/UnitConverter.Wpf](https://github.com/angularsen/UnitsNet/tree/master/Samples/UnitConverter.Wpf) for source code.
127131

128132
This example shows how you can create a dynamic unit converter, where the user selects the quantity to convert, such as `Length` or `Mass`, then selects to convert from `Meter` to `Centimeter` and types in a value for how many meters.
129133

134+
NOTE: There are still some limitations in the library that requires reflection to enumerate units for quantity and getting the abbreviation for a unit, when we want to dynamically enumerate and convert between units.
135+
136+
### <a name="example-app-hardcoded"></a>Example: Creating a unit converter app with hard coded quantities
137+
138+
If you can live with hard coding what quantities to convert between, then the following code snippet shows you one way to go about it:
139+
130140
```C#
131141
// Get quantities for populating quantity UI selector
132142
QuantityType[] quantityTypes = Enum.GetValues(typeof(QuantityType)).Cast<QuantityType>().ToArray();
133143

134144
// If Length is selected, get length units for populating from/to UI selectors
135145
LengthUnit[] lengthUnits = Length.Units;
136146

137-
// Perform conversion by using .ToString() on the selected units
147+
// Perform conversion using input value and selected from/to units
148+
double inputValue; // Obtain from textbox
149+
LengthUnit fromUnit, toUnit; // Obtain from ListBox selections
150+
double resultValue = Length.From(inputValue, fromUnit).As(toUnit);
151+
152+
// Alternatively, you can also convert using string representations of units
138153
double centimeters = UnitConverter.ConvertByName(5, "Length", "Meter", "Centimeter"); // 500
139154
double centimeters2 = UnitConverter.ConvertByAbbreviation(5, "Length", "m", "cm"); // 500
140155
```
141156

157+
### Example: WPF app using IValueConverter to parse quantities from input
158+
159+
Src: [Samples/WpfMVVMSample](https://github.com/angularsen/UnitsNet/tree/master/Samples/WpfMVVMSample)
160+
161+
![wpfmvvmsample_219w](https://user-images.githubusercontent.com/787816/34913417-094332e2-f8fd-11e7-9d8a-92db105fbbc9.png)
162+
163+
164+
The purpose of this app is to show how to create an `IValueConverter` in order to bind XAML to quantities.
165+
166+
NOTE: A lot of reflection and complexity was introduced due to not having a base type. See #371 for discussion on adding base types.
167+
142168
### <a name="precision"></a>Precision and Accuracy
143169

144170
A base unit is chosen for each unit class, represented by a double value (64-bit), and all conversions go via this unit. This means there will always be a small error in both representing other units than the base unit as well as converting between units.
@@ -217,6 +243,6 @@ http://www.nuget.org/packages/Microsoft.IoT.Devices (NuGet package)
217243
> Software for creating printable hex maps for use in pen and paper RPGs. Both
218244
> a user-friendly app and a high-level library for generating labelled hexmaps.
219245
220-
https://github.com/MartinEden/UnitsNet
246+
https://bitbucket.org/MartinEden/Crawlspace
221247

222248
*- Martin Eden, project maintainer*
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp1.0</TargetFramework>
5+
<AssemblyName>ConsoleApp-NetCore</AssemblyName>
6+
<OutputType>Exe</OutputType>
7+
<PackageId>ConsoleApp-NetCore</PackageId>
8+
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
9+
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
10+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
11+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
12+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="UnitsNet" Version="3.45.0" />
17+
</ItemGroup>
18+
19+
</Project>

Samples/ConsoleApp-NetCore/ConsoleApp-NetCore.xproj

Lines changed: 0 additions & 19 deletions
This file was deleted.

Samples/ConsoleApp-NetCore/project.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

Samples/Samples.sln

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27130.2020
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ConsoleApp-NetCore", "ConsoleApp-NetCore\ConsoleApp-NetCore.xproj", "{955A6CBF-C4E3-4C55-85C8-613E2CA4CCD7}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp-NetCore", "ConsoleApp-NetCore\ConsoleApp-NetCore.csproj", "{955A6CBF-C4E3-4C55-85C8-613E2CA4CCD7}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitConverter.Wpf", "UnitConverter.Wpf\UnitConverter.Wpf\UnitConverter.Wpf.csproj", "{D04EE35D-496A-4C83-A369-09B9B2BEAEEC}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfMVVMSample", "WpfMVVMSample\WpfMVVMSample\WpfMVVMSample.csproj", "{B72F9215-70FF-4155-89BC-9A02CC550447}"
711
EndProject
812
Global
913
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,8 +19,19 @@ Global
1519
{955A6CBF-C4E3-4C55-85C8-613E2CA4CCD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
1620
{955A6CBF-C4E3-4C55-85C8-613E2CA4CCD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
1721
{955A6CBF-C4E3-4C55-85C8-613E2CA4CCD7}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{D04EE35D-496A-4C83-A369-09B9B2BEAEEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{D04EE35D-496A-4C83-A369-09B9B2BEAEEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{D04EE35D-496A-4C83-A369-09B9B2BEAEEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{D04EE35D-496A-4C83-A369-09B9B2BEAEEC}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{B72F9215-70FF-4155-89BC-9A02CC550447}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{B72F9215-70FF-4155-89BC-9A02CC550447}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{B72F9215-70FF-4155-89BC-9A02CC550447}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{B72F9215-70FF-4155-89BC-9A02CC550447}.Release|Any CPU.Build.0 = Release|Any CPU
1830
EndGlobalSection
1931
GlobalSection(SolutionProperties) = preSolution
2032
HideSolutionNode = FALSE
2133
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {A78FD611-C7A6-472D-95CA-4B474F775CCA}
36+
EndGlobalSection
2237
EndGlobal
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Unit Converter WPF Sample App
2+
3+
This is a simple sample showing how UnitsNet can be used to create a generic unit converter, using all the quantities and units available in the UnitsNet library.
4+
5+
![image](https://user-images.githubusercontent.com/787816/34920961-9b697004-f97b-11e7-9e9a-51ff7142969b.png)
6+
7+
It allows you to convert a value from one unit to another, by first selecting the quantity (`Length`), then selecting the from/to units (`Meter` to `Centimeter`) and finally typing the numeric value (`15.3`).
8+
The resulting value (`1530`) is computed instantly and reacts to whenever the numeric value or the from/to unit selection changes.
9+
10+
This sample also highlights a limitation in the library that requires reflection in order to enumerate units for a selected quantity and to get the abbreviation for a unit, since the library does not provide a generic means to retrieve these without referencing types like `Length` and `LengthUnit` directly. There is definitely room for improvement in the library here.
11+
12+
### Dependencies
13+
http://mahapps.com/ - UI toolkit for WPF

0 commit comments

Comments
 (0)