Skip to content

Commit

Permalink
Add obsolete to nanoframework code for deprecated units (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilnthorp authored Feb 10, 2022
1 parent 72e53ef commit 8e1240f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private void GenerateConversionProperties()
/// <summary>
/// Gets a <see cref=""double""/> value of this quantity converted into <see cref=""{_unitEnumName}.{unit.SingularName}""/>
/// </summary>");
Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit));
Writer.WL($@"
public {_quantity.BaseType} {unit.PluralName} => As({_unitEnumName}.{unit.SingularName});
");
Expand Down Expand Up @@ -158,6 +159,7 @@ private void GenerateStaticFactoryMethods()
/// Creates a <see cref=""{_quantity.Name}""/> from <see cref=""{_unitEnumName}.{unit.SingularName}""/>.
/// </summary>
/// <exception cref=""ArgumentException"">If value is NaN or Infinity.</exception>");
Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit));
Writer.WL($@"
public static {_quantity.Name} From{unit.PluralName}({_quantity.BaseType} {valueParamName}) => new {_quantity.Name}({valueParamName}, {_unitEnumName}.{unit.SingularName});
");
Expand Down Expand Up @@ -247,5 +249,18 @@ private void GenerateConversionMethods()
");
}

/// <inheritdoc cref="GetObsoleteAttributeOrNull(string)"/>
internal static string? GetObsoleteAttributeOrNull(Quantity quantity) => GetObsoleteAttributeOrNull(quantity.ObsoleteText);

/// <inheritdoc cref="GetObsoleteAttributeOrNull(string)"/>
internal static string? GetObsoleteAttributeOrNull(Unit unit) => GetObsoleteAttributeOrNull(unit.ObsoleteText);

/// <summary>
/// Returns the Obsolete attribute if ObsoleteText has been defined on the JSON input - otherwise returns empty string
/// It is up to the consumer to wrap any padding/new lines in order to keep to correct indentation formats
/// </summary>
private static string? GetObsoleteAttributeOrNull(string obsoleteText) => string.IsNullOrWhiteSpace(obsoleteText)
? null
: $"[Obsolete(\"{obsoleteText}\")]";
}
}

0 comments on commit 8e1240f

Please sign in to comment.