diff --git a/CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs b/CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs index 2e9559300e..0c46ff1473 100644 --- a/CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs +++ b/CodeGen/Generators/NanoFrameworkGen/QuantityGenerator.cs @@ -131,6 +131,7 @@ private void GenerateConversionProperties() /// /// Gets a value of this quantity converted into /// "); + Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit)); Writer.WL($@" public {_quantity.BaseType} {unit.PluralName} => As({_unitEnumName}.{unit.SingularName}); "); @@ -158,6 +159,7 @@ private void GenerateStaticFactoryMethods() /// Creates a from . /// /// If value is NaN or Infinity."); + Writer.WLIfText(2, GetObsoleteAttributeOrNull(unit)); Writer.WL($@" public static {_quantity.Name} From{unit.PluralName}({_quantity.BaseType} {valueParamName}) => new {_quantity.Name}({valueParamName}, {_unitEnumName}.{unit.SingularName}); "); @@ -247,5 +249,18 @@ private void GenerateConversionMethods() "); } + /// + internal static string? GetObsoleteAttributeOrNull(Quantity quantity) => GetObsoleteAttributeOrNull(quantity.ObsoleteText); + + /// + internal static string? GetObsoleteAttributeOrNull(Unit unit) => GetObsoleteAttributeOrNull(unit.ObsoleteText); + + /// + /// 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 + /// + private static string? GetObsoleteAttributeOrNull(string obsoleteText) => string.IsNullOrWhiteSpace(obsoleteText) + ? null + : $"[Obsolete(\"{obsoleteText}\")]"; } }