Skip to content

Commit 8e1240f

Browse files
authored
Add obsolete to nanoframework code for deprecated units (#1041)
1 parent 72e53ef commit 8e1240f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private void GenerateConversionProperties()
131131
/// <summary>
132132
/// Gets a <see cref=""double""/> value of this quantity converted into <see cref=""{_unitEnumName}.{unit.SingularName}""/>
133133
/// </summary>");
134+
Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit));
134135
Writer.WL($@"
135136
public {_quantity.BaseType} {unit.PluralName} => As({_unitEnumName}.{unit.SingularName});
136137
");
@@ -158,6 +159,7 @@ private void GenerateStaticFactoryMethods()
158159
/// Creates a <see cref=""{_quantity.Name}""/> from <see cref=""{_unitEnumName}.{unit.SingularName}""/>.
159160
/// </summary>
160161
/// <exception cref=""ArgumentException"">If value is NaN or Infinity.</exception>");
162+
Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit));
161163
Writer.WL($@"
162164
public static {_quantity.Name} From{unit.PluralName}({_quantity.BaseType} {valueParamName}) => new {_quantity.Name}({valueParamName}, {_unitEnumName}.{unit.SingularName});
163165
");
@@ -247,5 +249,18 @@ private void GenerateConversionMethods()
247249
");
248250
}
249251

252+
/// <inheritdoc cref="GetObsoleteAttributeOrNull(string)"/>
253+
internal static string? GetObsoleteAttributeOrNull(Quantity quantity) => GetObsoleteAttributeOrNull(quantity.ObsoleteText);
254+
255+
/// <inheritdoc cref="GetObsoleteAttributeOrNull(string)"/>
256+
internal static string? GetObsoleteAttributeOrNull(Unit unit) => GetObsoleteAttributeOrNull(unit.ObsoleteText);
257+
258+
/// <summary>
259+
/// Returns the Obsolete attribute if ObsoleteText has been defined on the JSON input - otherwise returns empty string
260+
/// It is up to the consumer to wrap any padding/new lines in order to keep to correct indentation formats
261+
/// </summary>
262+
private static string? GetObsoleteAttributeOrNull(string obsoleteText) => string.IsNullOrWhiteSpace(obsoleteText)
263+
? null
264+
: $"[Obsolete(\"{obsoleteText}\")]";
250265
}
251266
}

0 commit comments

Comments
 (0)