Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,67 +167,67 @@ private void GenerateStaticFactoryMethods()
private void GenerateConversionMethods()
{
Writer.WL($@"
#region Conversion Methods

/// <summary>
/// Convert to the unit representation <paramref name=""unit"" />.
/// </summary>
/// <returns>Value converted to the specified unit.</returns>
public double As({_unitEnumName} unit) => GetValueAs(unit);

/// <summary>
/// Converts this {_quantity.Name} to another {_quantity.Name} with the unit representation <paramref name=""unit"" />.
/// </summary>
/// <returns>A {_quantity.Name} with the specified unit.</returns>
public {_quantity.Name} ToUnit({_unitEnumName} unit)
{{
var convertedValue = GetValueAs(unit);
return new {_quantity.Name}(convertedValue, unit);
}}

/// <summary>
/// Converts the current value + unit to the base unit.
/// This is typically the first step in converting from one unit to another.
/// </summary>
/// <returns>The value in the base unit representation.</returns>
private double GetValueInBaseUnit()
{{
return Unit switch
{{");
#region Conversion Methods

/// <summary>
/// Convert to the unit representation <paramref name=""unit"" />.
/// </summary>
/// <returns>Value converted to the specified unit.</returns>
public double As({_unitEnumName} unit) => GetValueAs(unit);

/// <summary>
/// Converts this {_quantity.Name} to another {_quantity.Name} with the unit representation <paramref name=""unit"" />.
/// </summary>
/// <returns>A {_quantity.Name} with the specified unit.</returns>
public {_quantity.Name} ToUnit({_unitEnumName} unit)
{{
var convertedValue = GetValueAs(unit);
return new {_quantity.Name}(convertedValue, unit);
}}

/// <summary>
/// Converts the current value + unit to the base unit.
/// This is typically the first step in converting from one unit to another.
/// </summary>
/// <returns>The value in the base unit representation.</returns>
private double GetValueInBaseUnit()
{{
return Unit switch
{{");
foreach (Unit unit in _quantity.Units)
{
var func = unit.FromUnitToBaseFunc.Replace("{x}", "_value");
Writer.WL($@"
{_unitEnumName}.{unit.SingularName} => {func},");
{_unitEnumName}.{unit.SingularName} => {func},");
}

Writer.WL($@"
_ => throw new NotImplementedException($""Can't convert {{Unit}} to base units."")
}};
}}
_ => throw new NotImplementedException($""Can't convert {{Unit}} to base units."")
}};
}}

private double GetValueAs({_unitEnumName} unit)
{{
if (Unit == unit)
return _value;
private double GetValueAs({_unitEnumName} unit)
{{
if (Unit == unit)
return _value;

var baseUnitValue = GetValueInBaseUnit();
var baseUnitValue = GetValueInBaseUnit();

return unit switch
{{");
return unit switch
{{");
foreach (Unit unit in _quantity.Units)
{
var func = unit.FromBaseToUnitFunc.Replace("{x}", "baseUnitValue");
Writer.WL($@"
{_unitEnumName}.{unit.SingularName} => {func},");
{_unitEnumName}.{unit.SingularName} => {func},");
}

Writer.WL(@"
_ => throw new NotImplementedException($""Can't convert {Unit} to {unit}."")
};
}
_ => throw new NotImplementedException($""Can't convert {Unit} to {unit}."")
};
}

#endregion");
#endregion");
}

/// <inheritdoc cref="GetObsoleteAttributeOrNull(string)"/>
Expand Down
25 changes: 25 additions & 0 deletions Common/UnitDefinitions/NominalPower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"Name": "NominalPower",
"BaseUnit": "WattPeak",
"XmlDocSummary": "The nominal power is the nameplate capacity of photovoltaic (PV) devices, such as solar cells, panels and systems, and is determined by measuring the electric current and voltage in a circuit, while varying the resistance under precisely defined conditions.",
"XmlDocRemarks": "https://en.wikipedia.org/wiki/Nominal_power_(photovoltaic)",
"Units": [
{
"SingularName": "WattPeak",
"PluralName": "WattsPeak",
"FromUnitToBaseFunc": "{x}",
"FromBaseToUnitFunc": "{x}",
"Prefixes": [ "Femto", "Pico", "Nano", "Micro", "Milli", "Deci", "Deca", "Kilo", "Mega", "Giga", "Tera", "Peta" ],
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "Wp" ]
},
{
"Culture": "fr-FR",
"Abbreviations": [ "Wc" ]
}
]
}
]
}
15 changes: 15 additions & 0 deletions Common/UnitEnumValues.g.json
Original file line number Diff line number Diff line change
Expand Up @@ -2018,5 +2018,20 @@
"SquareMeterKelvinPerKilowatt": 5,
"SquareMeterKelvinPerWatt": 4,
"SquareMillimeterKelvinPerWatt": 13
},
"NominalPower": {
"DecawattPeak": 1,
"DeciwattPeak": 2,
"FemtowattPeak": 3,
"GigawattPeak": 4,
"KilowattPeak": 5,
"MegawattPeak": 6,
"MicrowattPeak": 7,
"MilliwattPeak": 8,
"NanowattPeak": 9,
"PetawattPeak": 10,
"PicowattPeak": 11,
"TerawattPeak": 12,
"WattPeak": 13
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{6f14ad52-dce6-4e54-fd46-6ebbe10ac874}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<RootNamespace>UnitsNet</RootNamespace>
<AssemblyName>UnitsNet.NominalPower</AssemblyName>
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
<ItemGroup>
<Compile Include="..\Quantities\NominalPower.g.cs" />
<Compile Include="..\Units\NominalPowerUnit.g.cs" />
<Compile Include="..\Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib, Version=1.15.6.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
<HintPath>..\packages\nanoFramework.CoreLibrary.1.15.5\lib\mscorlib.dll</HintPath>
<Private>True</Private>
<SpecificVersion>True</SpecificVersion>
</Reference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
<ProjectExtensions>
<ProjectCapabilities>
<ProjectConfigurationsDeclaredAsItems />
</ProjectCapabilities>
</ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>UnitsNet.nanoFramework.NominalPower</id>
<version>6.0.0-pre019</version>
<title>Units.NET NominalPower - nanoFramework</title>
<authors>Andreas Gullberg Larsen,nanoframework</authors>
<owners>UnitsNet</owners>
<license type="expression">MIT-0</license>
<projectUrl>https://github.com/angularsen/UnitsNet</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Adds NominalPower units for Units.NET on .NET nanoFramework. For .NET or .NET Core, use UnitsNet instead.</description>
<iconUrl>https://raw.githubusercontent.com/angularsen/UnitsNet/ce85185429be345d77eb2ce09c99d59cc9ab8aed/Docs/Images/logo-32.png</iconUrl>
<releaseNotes>
</releaseNotes>
<copyright>Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com).</copyright>
<language>en-US</language>
<tags>nanoframework nominalpower unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable</tags>
<dependencies>
<dependency id="nanoFramework.CoreLibrary" version="1.15.5" />
</dependencies>
</metadata>
<files>
<file src="..\..\..\Artifacts\UnitsNet.NanoFramework\NominalPower\UnitsNet.*" target="lib" />
</files>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nanoFramework.CoreLibrary" version="1.15.5" targetFramework="netnanoframework10" />
</packages>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading