public static IndentedString GetExponents(IQuantityModel modelModel) { return(new IndentedString(8, $@" /// <summary> /// Gets the square. /// </summary> /// <value> /// The square. /// </value> public {PrefixesHelper.GetPrefixesAndUnitsInterface(modelModel)} Square => this.GetPrefixesAndUnits(2); /// <summary> /// Gets the cubic. /// </summary> /// <value> /// The cubic. /// </value> public {PrefixesHelper.GetPrefixesAndUnitsInterface(modelModel)} Cubic => this.GetPrefixesAndUnits(3); /// <summary> /// Gets the quartic. /// </summary> /// <value> /// The quartic. /// </value> public {PrefixesHelper.GetPrefixesAndUnitsInterface(modelModel)} Quartic => this.GetPrefixesAndUnits(4); /// <summary> /// Gets the quintic. /// </summary> /// <value> /// The quintic. /// </value> public {PrefixesHelper.GetPrefixesAndUnitsInterface(modelModel)} Quintic => this.GetPrefixesAndUnits(5); ")); }
public ITextOutput Generate(ICodeSetup codeSetup, ICodeGeneratorSetup codeGeneratorSetup, IProject target, IQuantityModel model, ICodeRun run, long index) { return(new TextOutput(new IndentedString($@" // -------------------------------------------------------------------------------------------------------------------- // <copyright file=""{run.FileName}"" company=""Hukano""> // Copyright (c) Hukano. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // </copyright> // -------------------------------------------------------------------------------------------------------------------- // <auto-generated /> namespace {NamespaceHelper.CombineNamespaces(target.RootNamespace, run.Namespace)} {{ {UsingsHelper.GetUsings(codeSetup.UseGlobalUsings | codeGeneratorSetup.UseGlobalUsings, 4, codeSetup.Usings, codeGeneratorSetup.Usings)} /// <summary> /// UnitSelector for <see cref=""{model.Name}""/>. /// </summary> [GeneratedCode(""{this.GetType().FullName}"", ""{this.GetType().Assembly.GetName().Version}"")] public class {model.Name}UnitSelector : IExponentSelector<{PrefixesHelper.GetPrefixesAndUnitsInterface(model)}>, {PrefixesHelper.GetPrefixesAndUnitsInterface(model)} {{ private int actualExponent = 1; private Prefix actualPrefix; /// <summary> /// Gets the base unit. /// </summary> /// <value> /// The base unit. /// </value> public Expression BaseUnit => UnitDefinitions.{model.BaseUnit}; /// <summary> /// Gets the default units. /// </summary> /// <returns> /// An <see cref=""IEnumerable{{IUnit}}"" />. /// </returns> public IEnumerable<IUnit> GetDefaultUnits() {{ {this.GetDefaultUnits(model.DefaultUnits)} }} {ExponentsHelper.GetExponents(model)} {PrefixesHelper.GetPrefixes(model)} {UnitsHelper.GetUnits(model)} /// <summary> /// Specifies the prefix by the specified factor. /// </summary> /// <param name=""factor"">The factor.</param> /// <returns>The available units.</returns> public {PrefixesHelper.GetUnitsInterface(model)} By(double factor) {{ return this.GetUnits(new FactoredPrefix(factor)); }} /// <summary> /// Specifies the exponent. /// </summary> /// <param name=""exponent"">The exponent.</param> public void SpecifyExponent(int exponent) {{ this.actualExponent = exponent; }} /// <summary> /// Specifies the prefix. /// </summary> /// <param name=""prefix"">The prefix.</param> public void SpecifyPrefix(Prefix prefix) {{ this.actualPrefix = prefix; }} /// <summary> /// Selects the unit based on the specified magnitude, prefix and base unit. /// </summary> /// <param name=""unit"">The unit.</param> /// <returns> /// An <see cref=""Expression""/>. /// </returns> public Expression SpecifyUnit(IUnit unit) {{ return UnitSelectorHelper.CreateExpression(ref this.actualExponent, ref this.actualPrefix, unit); }} /// <summary> /// Gets the prefixes and unit selector. /// </summary> /// <param name=""exponent"">The exponent.</param> /// <returns> /// The available prefixes and units. /// </returns> private {PrefixesHelper.GetPrefixesAndUnitsInterface(model)} GetPrefixesAndUnits(int exponent) {{ this.SpecifyExponent(exponent); return this; }} /// <summary> /// Gets the unit selector. /// </summary> /// <param name=""prefix"">The prefix.</param> /// <returns>The available units.</returns> private {PrefixesHelper.GetUnitsInterface(model)} GetUnits(Prefix prefix) {{ this.SpecifyPrefix(prefix); return this; }} }} }} "))); }