Skip to content

Commit

Permalink
Add converters.
Browse files Browse the repository at this point in the history
WPF IValueConverters as MarkupExtensions
JsonConverters.
TypeConverters for Units and Quanities.
  • Loading branch information
JohanLarsson committed Dec 3, 2015
1 parent 4d51533 commit 8748d77
Show file tree
Hide file tree
Showing 323 changed files with 33,687 additions and 6,495 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ $tf*/
packages/*
Gu.Units.Generator/Templates/*.txt
publish/*
Generator/*
45 changes: 7 additions & 38 deletions Gu.Units.Fsharp.Tests/Gu.Units.Fsharp.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,42 +86,11 @@
</Target>
-->
<Import Project="..\.paket\paket.targets" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v3.0' Or $(TargetFrameworkVersion) == 'v3.5')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net20\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net40\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="($(TargetFrameworkIdentifier) == 'WindowsPhoneApp') Or ($(TargetFrameworkIdentifier) == '.NETCore') Or ($(TargetFrameworkIdentifier) == 'WindowsPhone' And ($(TargetFrameworkVersion) == 'v8.0' Or $(TargetFrameworkVersion) == 'v8.1')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch') Or ($(TargetFrameworkIdentifier) == 'Xamarin.iOS') Or ($(TargetFrameworkIdentifier) == 'Xamarin.Mac') Or ($(TargetFrameworkProfile) == 'Profile7') Or ($(TargetFrameworkProfile) == 'Profile31') Or ($(TargetFrameworkProfile) == 'Profile32') Or ($(TargetFrameworkProfile) == 'Profile44') Or ($(TargetFrameworkProfile) == 'Profile49') Or ($(TargetFrameworkProfile) == 'Profile78') Or ($(TargetFrameworkProfile) == 'Profile84') Or ($(TargetFrameworkProfile) == 'Profile111') Or ($(TargetFrameworkProfile) == 'Profile151') Or ($(TargetFrameworkProfile) == 'Profile157') Or ($(TargetFrameworkProfile) == 'Profile259')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</Project>
45 changes: 7 additions & 38 deletions Gu.Units.Generator.Tests/Gu.Units.Generator.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,11 @@
</Target>
-->
<Import Project="..\.paket\paket.targets" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v3.0' Or $(TargetFrameworkVersion) == 'v3.5')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net20\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net40\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="($(TargetFrameworkIdentifier) == 'WindowsPhoneApp') Or ($(TargetFrameworkIdentifier) == '.NETCore') Or ($(TargetFrameworkIdentifier) == 'WindowsPhone' And ($(TargetFrameworkVersion) == 'v8.0' Or $(TargetFrameworkVersion) == 'v8.1')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch') Or ($(TargetFrameworkIdentifier) == 'Xamarin.iOS') Or ($(TargetFrameworkIdentifier) == 'Xamarin.Mac') Or ($(TargetFrameworkProfile) == 'Profile7') Or ($(TargetFrameworkProfile) == 'Profile31') Or ($(TargetFrameworkProfile) == 'Profile32') Or ($(TargetFrameworkProfile) == 'Profile44') Or ($(TargetFrameworkProfile) == 'Profile49') Or ($(TargetFrameworkProfile) == 'Profile78') Or ($(TargetFrameworkProfile) == 'Profile84') Or ($(TargetFrameworkProfile) == 'Profile111') Or ($(TargetFrameworkProfile) == 'Profile151') Or ($(TargetFrameworkProfile) == 'Profile157') Or ($(TargetFrameworkProfile) == 'Profile259')">
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</Project>
15 changes: 3 additions & 12 deletions Gu.Units.Generator/Descriptors/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -18,6 +17,7 @@ public class Settings
private readonly ParentCollection<Settings, DerivedUnit> _derivedUnits;
private readonly ParentCollection<Settings, SiUnit> _siUnits;
private readonly ObservableCollection<Prefix> _prefixes = new ObservableCollection<Prefix>();

protected Settings()
{
_derivedUnits = new ParentCollection<Settings, DerivedUnit>(this, (unit, settings) => unit.Settings = settings);
Expand Down Expand Up @@ -115,18 +115,9 @@ public ObservableCollection<Prefix> Prefixes
get { return _prefixes; }
}

public IEnumerable<IUnit> AllUnits
{
get { return SiUnits.Concat<IUnit>(DerivedUnits); }
}
public IReadOnlyList<IUnit> AllUnits => SiUnits.Concat<IUnit>(DerivedUnits).ToList();

public IEnumerable<Quantity> Quantities
{
get
{
return AllUnits.Select(x => x.Quantity).ToArray();
}
}
public IReadOnlyList<Quantity> Quantities => AllUnits.Select(x => x.Quantity).ToList();

public static Settings FromFile(string fullFileName)
{
Expand Down
170 changes: 169 additions & 1 deletion Gu.Units.Generator/GeneratorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
</Conversion>
<Conversion>
<ClassName>Bars</ClassName>
<Symbol>bar</Symbol>
Expand All @@ -287,6 +287,33 @@
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>NewtonsPerSquareMillimetre</ClassName>
<Symbol>N⋅mm⁻²</Symbol>
<Formula>
<ConversionFactor>1000000</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>KilonewtonsPerSquareMillimetre</ClassName>
<Symbol>kN⋅mm⁻²</Symbol>
<Formula>
<ConversionFactor>1000000000</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>NewtonsPerSquareMetre</ClassName>
<Symbol>N/m²</Symbol>
<Formula>
<ConversionFactor>1</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
</Conversions>
<Parts>
<UnitAndPower>
Expand Down Expand Up @@ -1243,6 +1270,147 @@
</UnitAndPower>
</Parts>
</DerivedUnit>
<DerivedUnit>
<ClassName>MetresPerUnitless</ClassName>
<Symbol>m/ul</Symbol>
<QuantityName>LengthPerUnitless</QuantityName>
<Conversions>
<Conversion>
<ClassName>MillimetresPerPercent</ClassName>
<Symbol>mm/%</Symbol>
<Formula>
<ConversionFactor>0.1</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>MicrometresPerPercent</ClassName>
<Symbol>µm/%</Symbol>
<Formula>
<ConversionFactor>9.9999999999999991E-05</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>NanometresPerPercent</ClassName>
<Symbol>nm/%</Symbol>
<Formula>
<ConversionFactor>1.0000000000000001E-07</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>MetresPerPercent</ClassName>
<Symbol>m/%</Symbol>
<Formula>
<ConversionFactor>100</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
</Conversions>
<Parts>
<UnitAndPower>
<UnitName>Metres</UnitName>
<Power>1</Power>
</UnitAndPower>
<UnitAndPower>
<UnitName>Scalar</UnitName>
<Power>-1</Power>
</UnitAndPower>
</Parts>
</DerivedUnit>
<DerivedUnit>
<ClassName>RadiansPerUnitless</ClassName>
<Symbol>rad/ul</Symbol>
<QuantityName>AnglePerUnitless</QuantityName>
<Conversions>
<Conversion>
<ClassName>DegreesPerPercent</ClassName>
<Symbol>°/%</Symbol>
<Formula>
<ConversionFactor>1.7453292519943295</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>RadiansPerPercent</ClassName>
<Symbol>rad/%</Symbol>
<Formula>
<ConversionFactor>100</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
</Conversions>
<Parts>
<UnitAndPower>
<UnitName>Radians</UnitName>
<Power>1</Power>
</UnitAndPower>
<UnitAndPower>
<UnitName>Scalar</UnitName>
<Power>-1</Power>
</UnitAndPower>
</Parts>
</DerivedUnit>
<DerivedUnit>
<ClassName>NewtonsPerUnitless</ClassName>
<Symbol>N/ul</Symbol>
<QuantityName>ForcePerUnitless</QuantityName>
<Conversions>
<Conversion>
<ClassName>NewtonsPerPercent</ClassName>
<Symbol>N/%</Symbol>
<Formula>
<ConversionFactor>100</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>KilonewtonsPerPercent</ClassName>
<Symbol>kN/%</Symbol>
<Formula>
<ConversionFactor>100000</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>MeganewtonsPerPercent</ClassName>
<Symbol>MN/%</Symbol>
<Formula>
<ConversionFactor>100000000</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
<Conversion>
<ClassName>GiganewtonsPerPercent</ClassName>
<Symbol>GN/%</Symbol>
<Formula>
<ConversionFactor>100000000000</ConversionFactor>
<Offset>0</Offset>
</Formula>
<Conversions />
</Conversion>
</Conversions>
<Parts>
<UnitAndPower>
<UnitName>Newtons</UnitName>
<Power>1</Power>
</UnitAndPower>
<UnitAndPower>
<UnitName>Scalar</UnitName>
<Power>-1</Power>
</UnitAndPower>
</Parts>
</DerivedUnit>
</DerivedUnits>
<SiUnits>
<SiUnit>
Expand Down
Loading

0 comments on commit 8748d77

Please sign in to comment.