Skip to content

Commit

Permalink
TypeConverters for Units
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Nov 22, 2015
1 parent 24f9597 commit 4d51533
Show file tree
Hide file tree
Showing 69 changed files with 5,150 additions and 80 deletions.
62 changes: 40 additions & 22 deletions Gu.Units.Generator/Gu.Units.Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Templates\UnitTypeConverter.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>UnitTypeConverter.txt</LastGenOutput>
</EmbeddedResource>
<Resource Include="Templates\UnitTypeConverterGenerator.txt">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>UnitTypeConverterGenerator.tt</DependentUpon>
</Resource>
<Resource Include="Templates\UnitTypeConverter.txt">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>UnitTypeConverter.tt</DependentUpon>
</Resource>
<EmbeddedResource Include="Templates\UnitTypeConverterGenerator.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>UnitTypeConverterGenerator.txt</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand All @@ -153,40 +171,40 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
<Content Include="Templates\Enumerable.tt">
<EmbeddedResource Include="Templates\Enumerable.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Enumerable.txt</LastGenOutput>
</Content>
<Content Include="Templates\EnumerableGenerator.tt">
</EmbeddedResource>
<EmbeddedResource Include="Templates\EnumerableGenerator.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>EnumerableGenerator.txt</LastGenOutput>
</Content>
<Content Include="Templates\TypeConverterGenerator.tt">
</EmbeddedResource>
<EmbeddedResource Include="Templates\QuantityTypeConverterGenerator.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>TypeConverterGenerator.txt</LastGenOutput>
</Content>
<Resource Include="Templates\TypeConverterGenerator.txt">
<LastGenOutput>QuantityTypeConverterGenerator.txt</LastGenOutput>
</EmbeddedResource>
<Resource Include="Templates\QuantityTypeConverterGenerator.txt">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>TypeConverterGenerator.tt</DependentUpon>
<DependentUpon>QuantityTypeConverterGenerator.tt</DependentUpon>
</Resource>
<Content Include="Templates\UnitGenerator.tt">
<EmbeddedResource Include="Templates\UnitGenerator.tt">
<SubType>Code</SubType>
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>UnitGenerator.txt</LastGenOutput>
</Content>
<Content Include="Templates\Quantity.tt">
</EmbeddedResource>
<EmbeddedResource Include="Templates\Quantity.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Quantity.txt</LastGenOutput>
</Content>
<Content Include="Templates\QuantityGenerator.tt">
</EmbeddedResource>
<EmbeddedResource Include="Templates\QuantityGenerator.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>QuantityGenerator.txt</LastGenOutput>
</Content>
<Content Include="Templates\Unit.tt">
</EmbeddedResource>
<EmbeddedResource Include="Templates\Unit.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Unit.txt</LastGenOutput>
</Content>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand All @@ -207,14 +225,14 @@
</Resource>
</ItemGroup>
<ItemGroup>
<Content Include="Templates\TypeConverter.tt">
<EmbeddedResource Include="Templates\QuantityTypeConverter.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>TypeConverter.txt</LastGenOutput>
</Content>
<Resource Include="Templates\TypeConverter.txt">
<LastGenOutput>QuantityTypeConverter.txt</LastGenOutput>
</EmbeddedResource>
<Resource Include="Templates\QuantityTypeConverter.txt">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>TypeConverter.tt</DependentUpon>
<DependentUpon>QuantityTypeConverter.tt</DependentUpon>
</Resource>
<Resource Include="Templates\Unit.txt">
<AutoGen>True</AutoGen>
Expand Down
2 changes: 1 addition & 1 deletion Gu.Units.Generator/Templates/EnumerableGenerator.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ include file="$(SolutionDir)\Packages\T4.TemplateFileManager\tools\ttinc\TemplateFilemanager.CS.ttinclude" #>
<#@ include file="$(SolutionDir)Packages\T4.TemplateFileManager\tools\ttinc\TemplateFilemanager.CS.ttinclude" #>
<#@ output extension=".txt" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(TargetPath)" #>
Expand Down
8 changes: 7 additions & 1 deletion Gu.Units.Generator/Templates/EnumerableGenerator.txt
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
ErrorGeneratingOutput

Read Settings found 32 quantities
//-> Enumerable.generated.cs
// Generated helper templates
// Gu.Units\Gu.Units\EnumerableGenerator.txt4
// Generated items
// Gu.Units\Gu.Units\Enumerable.generated.cs
4 changes: 2 additions & 2 deletions Gu.Units.Generator/Templates/QuantityGenerator.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ include file="$(SolutionDir)\Packages\T4.TemplateFileManager\tools\ttinc\TemplateFilemanager.CS.ttinclude" #>
<#@ include file="$(SolutionDir)Packages\T4.TemplateFileManager\tools\ttinc\TemplateFilemanager.CS.ttinclude" #>
<#@ output extension=".txt" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(TargetPath)" #>
Expand All @@ -19,7 +19,7 @@ fileManager.CanOverwriteExistingFile = true;
var paramTmpl = ParamTextTemplate.Create(this.Host);
var session = ParamTextTemplate.GetSessionObject();
var settings = Settings.Instance;
this.Write(string.Format("Read Settings found {0} units", settings.Quantities.Count()));
this.Write(string.Format("Read Settings and found {0} units", settings.Quantities.Count()));
foreach (var quantity in settings.Quantities)
{
fileManager.StartNewFile(quantity.ClassName + ".generated." + Settings.Extension , Settings.ProjectName, null, null);
Expand Down
101 changes: 100 additions & 1 deletion Gu.Units.Generator/Templates/QuantityGenerator.txt
Original file line number Diff line number Diff line change
@@ -1 +1,100 @@
ErrorGeneratingOutput

Read Settings and found 32 units
//-> Acceleration.generated.cs

//-> Angle.generated.cs

//-> AngularAcceleration.generated.cs

//-> AngularJerk.generated.cs

//-> AngularSpeed.generated.cs

//-> Area.generated.cs

//-> Capacitance.generated.cs

//-> Current.generated.cs

//-> Density.generated.cs

//-> ElectricCharge.generated.cs

//-> Energy.generated.cs

//-> Flexibility.generated.cs

//-> Force.generated.cs

//-> Frequency.generated.cs

//-> Inductance.generated.cs

//-> Jerk.generated.cs

//-> Length.generated.cs

//-> LuminousIntensity.generated.cs

//-> Mass.generated.cs

//-> Power.generated.cs

//-> Pressure.generated.cs

//-> Resistance.generated.cs

//-> SpecificEnergy.generated.cs

//-> Speed.generated.cs

//-> Stiffness.generated.cs

//-> Temperature.generated.cs

//-> Time.generated.cs

//-> Torque.generated.cs

//-> Unitless.generated.cs

//-> Voltage.generated.cs

//-> Volume.generated.cs

//-> VolumetricFlow.generated.cs
// Generated helper templates
// Gu.Units\Gu.Units\QuantityGenerator.txt4
// Generated items
// Gu.Units\Gu.Units\Jerk.generated.cs
// Gu.Units\Gu.Units\AngularJerk.generated.cs
// Gu.Units\Gu.Units\AngularAcceleration.generated.cs
// Gu.Units\Gu.Units\Flexibility.generated.cs
// Gu.Units\Gu.Units\Capacitance.generated.cs
// Gu.Units\Gu.Units\Inductance.generated.cs
// Gu.Units\Gu.Units\ElectricCharge.generated.cs
// Gu.Units\Gu.Units\SpecificEnergy.generated.cs
// Gu.Units\Gu.Units\Resistance.generated.cs
// Gu.Units\Gu.Units\Voltage.generated.cs
// Gu.Units\Gu.Units\VolumetricFlow.generated.cs
// Gu.Units\Gu.Units\Stiffness.generated.cs
// Gu.Units\Gu.Units\Torque.generated.cs
// Gu.Units\Gu.Units\Acceleration.generated.cs
// Gu.Units\Gu.Units\Frequency.generated.cs
// Gu.Units\Gu.Units\AngularSpeed.generated.cs
// Gu.Units\Gu.Units\Speed.generated.cs
// Gu.Units\Gu.Units\Power.generated.cs
// Gu.Units\Gu.Units\Energy.generated.cs
// Gu.Units\Gu.Units\Density.generated.cs
// Gu.Units\Gu.Units\Pressure.generated.cs
// Gu.Units\Gu.Units\Force.generated.cs
// Gu.Units\Gu.Units\Volume.generated.cs
// Gu.Units\Gu.Units\Area.generated.cs
// Gu.Units\Gu.Units\LuminousIntensity.generated.cs
// Gu.Units\Gu.Units\Current.generated.cs
// Gu.Units\Gu.Units\Unitless.generated.cs
// Gu.Units\Gu.Units\Angle.generated.cs
// Gu.Units\Gu.Units\Temperature.generated.cs
// Gu.Units\Gu.Units\Time.generated.cs
// Gu.Units\Gu.Units\Length.generated.cs
// Gu.Units\Gu.Units\Mass.generated.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
Expand All @@ -7,7 +7,7 @@
<#@ parameter name="QuantityMetaData" type="Gu.Units.Generator.Quantity" #>
<#@ output extension=".txt" #>
<#
// Template used by TypeConverterGenerator.tt
// Template used by QuantityTypeConverterGenerator.tt
Quantity quantity = null;
if(QuantityMetaData != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ include file="$(SolutionDir)\Packages\T4.TemplateFileManager\tools\ttinc\TemplateFilemanager.CS.ttinclude" #>
<#@ include file="$(SolutionDir)Packages\T4.TemplateFileManager\tools\ttinc\TemplateFilemanager.CS.ttinclude" #>
<#@ output extension=".txt" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(TargetPath)" #>
Expand All @@ -25,7 +25,7 @@ foreach (var quantity in settings.Quantities)
var fileName = quantity.ClassName + "TypeConverter.generated." + Settings.Extension;
fileManager.StartNewFile(fileName , Settings.ProjectName, null, null);
session["QuantityMetaData"] = quantity;
string output = paramTmpl.TransformText("TypeConverter.tt", session);
string output = paramTmpl.TransformText("QuantityTypeConverter.tt", session);
this.Write(output);
}

Expand Down
2 changes: 1 addition & 1 deletion Gu.Units.Generator/Templates/Unit.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
Expand Down
20 changes: 6 additions & 14 deletions Gu.Units.Generator/Templates/UnitGenerator.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ include file="$(SolutionDir)\Packages\T4.TemplateFileManager\tools\ttinc\TemplateFilemanager.CS.ttinclude" #>
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ include file="$(SolutionDir)Packages\T4.TemplateFileManager\tools\ttinc\TemplateFilemanager.CS.ttinclude" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="$(TargetPath)" #>
<#@ import namespace="Gu.Units.Generator" #>
Expand All @@ -19,27 +19,19 @@ fileManager.CanOverwriteExistingFile = true;
var paramTmpl = ParamTextTemplate.Create(this.Host);
var session = ParamTextTemplate.GetSessionObject();
var settings = Settings.Instance;
this.Write(string.Format("Read Settings found {0} units", settings.SiUnits.Count));
this.Write(string.Format("Read Settings and found {0} si units and {1} derived units", settings.SiUnits.Count, settings.DerivedUnits.Count));

foreach (var unit in settings.SiUnits)
foreach (var unit in settings.SiUnits.Concat<IUnit>(settings.DerivedUnits))
{
session["UnitMetaData"] = unit;

fileManager.StartNewFile(unit.Quantity.ClassName + "Unit.generated." + Settings.Extension, Settings.ProjectName, Settings.FolderName, null);
var fileName = unit.Quantity.ClassName + "Unit.generated." + Settings.Extension;
fileManager.StartNewFile(fileName, Settings.ProjectName, Settings.FolderName, null);
var output = paramTmpl.TransformText("Unit.tt", session);
this.Write(output);
//this.WriteLine();
}

foreach (var unit in settings.DerivedUnits)
{
session["UnitMetaData"] = unit;

fileManager.StartNewFile(unit.Quantity.ClassName + "Unit.generated." + Settings.Extension, Settings.ProjectName, Settings.FolderName, null);
var output = paramTmpl.TransformText("Unit.tt", session);
this.Write(output);
//this.WriteLine();
}
//session["UnitMetaData"] = null;
fileManager.Process();
#>
Loading

0 comments on commit 4d51533

Please sign in to comment.