Skip to content

Commit 25b0fcc

Browse files
authored
Add [DebuggerTypeProxy] to generated quantities (#1390)
``` /// <summary> /// Serves as a debug display proxy for a quantity, providing a convenient way to view various components of the /// quantity during debugging. /// </summary> /// <remarks> /// This struct provides a structured view of a quantity's components such as abbreviation, unit, value, and convertor /// during debugging. /// Each component is represented by a nested struct, which can be expanded in the debugger to inspect its properties. /// </remarks> internal readonly struct QuantityDisplay(IQuantity quantity) ``` This is added to all quantities such: ``` [DataContract] [DebuggerTypeProxy(typeof(QuantityDisplay))] public readonly partial struct Mass : ``` There are 4 properties visible, each of which can be further expanded: 1. `Abbreviation`: displays the `DefaultAbbreviation` and expands with the list all abbreviations for the current unit, also holds a property with the possible unit conversions (displaying the target abbreviation in the `ConvertedQuantity[]`) 2. `Unit`: displays the `Unit` such as `Milligram` and expands to the list of other options, where every other options expands to the respective `ConvertedQuantity` (much like a _smart enum_). 3. `Value`: displays the `DoubleValue` by default and expands with the `IsDecimal`, `DecimalValue` and `DoubleValue` properties 4. `ValueConversions`: displays the output of the `QuantityToString` by default and expands with the list of possible QuantityToString options (currently only has the `GeneralFormat` and `ShortFormat` properties) as well as the list of possible unit conversions (`ConvertedQuantity[]`) Note that I've had to carefully pick the property names such that they are sorted (more or less) how I wanted, as visual studio sorts them alphabetically, not by the order of declaration. Perhaps there (is / would one day be) an option to change that behavior but, yeah- that's it for now. I've only tested this with Visual Studio 2022 - but i don't see why there should by any issues with the other IDEs. I did observe that not all things are always displayed on net48 (sometimes there is the _"..requires thread to complete.."). ![image](https://github.com/angularsen/UnitsNet/assets/5253184/3569a22b-de5e-46a3-853f-969d0ee3763c) ![image](https://github.com/angularsen/UnitsNet/assets/5253184/73aa6751-3cdf-4d30-a451-7a486550c3bd) ![image](https://github.com/angularsen/UnitsNet/assets/5253184/b6570b4c-f552-40b9-9fc8-62717712aa62) ![image](https://github.com/angularsen/UnitsNet/assets/5253184/5c49f049-2d99-4e87-b938-38b090ef5f98) ![image](https://github.com/angularsen/UnitsNet/assets/5253184/4ebc3c79-6518-4dd3-8dfd-e5ddb69b884f) If we open the visualizer view with the list from the `QuantityToUnit` we get a nice little table: ![image](https://github.com/angularsen/UnitsNet/assets/5253184/48a100b8-02be-4283-b2e1-5a0537717ccd)
1 parent cecef38 commit 25b0fcc

File tree

126 files changed

+393
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+393
-0
lines changed

CodeGen/Generators/UnitsNetGen/QuantityGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public string Generate()
3737
Writer.WL(GeneratedFileHeader);
3838
Writer.WL(@"
3939
using System;
40+
using System.Diagnostics;
4041
using System.Diagnostics.CodeAnalysis;
4142
using System.Globalization;
4243
using System.Linq;
@@ -64,6 +65,7 @@ namespace UnitsNet
6465
Writer.WLIfText(1, GetObsoleteAttributeOrNull(_quantity));
6566
Writer.WL(@$"
6667
[DataContract]
68+
[DebuggerTypeProxy(typeof(QuantityDisplay))]
6769
public readonly partial struct {_quantity.Name} :
6870
{(_quantity.GenerateArithmetic ? "IArithmeticQuantity" : "IQuantity")}<{_quantity.Name}, {_unitEnumName}, {_quantity.ValueType}>,");
6971

UnitsNet/GeneratedCode/Quantities/AbsorbedDoseOfIonizingRadiation.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Acceleration.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AmountOfSubstance.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AmplitudeRatio.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Angle.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ApparentEnergy.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ApparentPower.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Area.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AreaDensity.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/AreaMomentOfInertia.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/BitRate.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/BrakeSpecificFuelConsumption.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Capacitance.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/CoefficientOfThermalExpansion.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Compressibility.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Density.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/Duration.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/DynamicViscosity.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ElectricAdmittance.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ElectricCharge.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ElectricChargeDensity.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ElectricConductance.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ElectricConductivity.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitsNet/GeneratedCode/Quantities/ElectricCurrent.g.cs

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)