-
Notifications
You must be signed in to change notification settings - Fork 0
DiGi.Unit.Classes
An attribute used to categorize enums, implementing serialization and naming contracts.
public sealed class CategoryAttribute : System.Attribute, DiGi.Core.Interfaces.ISerializableObject, DiGi.Core.Interfaces.ICloneableObject<DiGi.Core.Interfaces.ISerializableObject>, DiGi.Core.Interfaces.ICloneableObject, DiGi.Core.Interfaces.IObject, DiGi.Core.Interfaces.INamedObjectInheritance System.Object → System.Attribute → CategoryAttribute
Implements DiGi.Core.Interfaces.ISerializableObject, DiGi.Core.Interfaces.ICloneableObject<DiGi.Core.Interfaces.ISerializableObject>, DiGi.Core.Interfaces.ICloneableObject, DiGi.Core.Interfaces.IObject, DiGi.Core.Interfaces.INamedObject
Initializes a new instance of the CategoryAttribute class by copying an existing category attribute.
public CategoryAttribute(DiGi.Unit.Classes.CategoryAttribute category);category CategoryAttribute
The source category attribute to copy.
Initializes a new instance of the CategoryAttribute class using a specified unit category.
public CategoryAttribute(DiGi.Unit.Enums.UnitCategory unitCategory);unitCategory UnitCategory
The unit category to assign.
Initializes a new instance of the CategoryAttribute class from a JSON object.
public CategoryAttribute(System.Text.Json.Nodes.JsonObject jsonObject);jsonObject System.Text.Json.Nodes.JsonObject
The JSON object containing category data.
Gets the name associated with the category.
public string Name { get; }Implements Name
Gets the UnitCategory enum value corresponding to the current name.
public System.Nullable<DiGi.Unit.Enums.UnitCategory> UnitCategory { get; }Creates a clone of the current category attribute.
public DiGi.Core.Interfaces.ISerializableObject? Clone();Implements Clone()
DiGi.Core.Interfaces.ISerializableObject
A cloned DiGi.Core.Interfaces.ISerializableObject instance.
Populates the current category attribute from a JSON object.
public bool FromJsonObject(System.Text.Json.Nodes.JsonObject? jsonObject);jsonObject System.Text.Json.Nodes.JsonObject
The JSON object to read data from.
Implements FromJsonObject(JsonObject)
System.Boolean
True if the population was successful; otherwise, false.
Converts the current category attribute to a JSON object.
public System.Text.Json.Nodes.JsonObject? ToJsonObject();Implements ToJsonObject()
System.Text.Json.Nodes.JsonObject
A System.Text.Json.Nodes.JsonObject representation of the attribute.
Implicitly converts a UnitCategory value to a CategoryAttribute.
public static DiGi.Unit.Classes.CategoryAttribute implicit operator DiGi.Unit.Classes.CategoryAttribute(DiGi.Unit.Enums.UnitCategory unitCategory);unitCategory UnitCategory
The unit category to convert.
CategoryAttribute
A new CategoryAttribute instance.
Implicitly converts a string name to a CategoryAttribute.
public static DiGi.Unit.Classes.CategoryAttribute implicit operator DiGi.Unit.Classes.CategoryAttribute(string name);name System.String
The category name to convert.
CategoryAttribute
A new CategoryAttribute instance.
Represents an attribute that defines a unit of measurement based on a conversion factor.
public class FactorUnitAttribute : DiGi.Unit.Classes.UnitAttributeInheritance System.Object → System.Attribute → UnitAttribute → FactorUnitAttribute
Derived
↳ LinearUnitAttribute
Initializes a new instance of the FactorUnitAttribute class by copying an existing instance.
public FactorUnitAttribute(DiGi.Unit.Classes.FactorUnitAttribute factorUnit);factorUnit FactorUnitAttribute
The source attribute to copy from.
Initializes a new instance of the FactorUnitAttribute class.
public FactorUnitAttribute(string? name, string? symbol, double factor);name System.String
The name of the unit.
symbol System.String
The symbol representing the unit.
factor System.Double
The conversion factor for the unit.
Initializes a new instance of the FactorUnitAttribute class from a JSON object.
public FactorUnitAttribute(System.Text.Json.Nodes.JsonObject jsonObject);jsonObject System.Text.Json.Nodes.JsonObject
The JSON object containing the attribute data.
Gets the conversion factor used for value transformations.
public double Factor { get; }Creates a clone of the current FactorUnitAttribute instance.
public override DiGi.Core.Interfaces.ISerializableObject? Clone();Implements Clone()
DiGi.Core.Interfaces.ISerializableObject
A new DiGi.Core.Interfaces.ISerializableObject representing the cloned attribute.
Converts a value from the base unit to this specific unit by multiplying it by the factor.
public override double From(double value);value System.Double
The numeric value to convert.
System.Double
The converted value.
Converts a value from this specific unit back to the base unit by dividing it by the factor.
public override double To(double value);value System.Double
The numeric value to convert.
System.Double
The converted value.
Represents an attribute for linear unit conversion that incorporates both a multiplication factor and an additive offset.
public class LinearUnitAttribute : DiGi.Unit.Classes.FactorUnitAttributeInheritance System.Object → System.Attribute → UnitAttribute → FactorUnitAttribute → LinearUnitAttribute
Initializes a new instance of the LinearUnitAttribute class by copying an existing linear unit attribute.
public LinearUnitAttribute(DiGi.Unit.Classes.LinearUnitAttribute linearUnit);linearUnit LinearUnitAttribute
The source LinearUnitAttribute to copy from.
Initializes a new instance of the LinearUnitAttribute class with specified name, symbol, factor, and offset.
public LinearUnitAttribute(string? name, string? symbol, double factor, double offset);name System.String
The display name of the unit.
symbol System.String
The symbol representing the unit.
factor System.Double
The multiplication factor used for conversion.
offset System.Double
The additive offset used for conversion.
Initializes a new instance of the LinearUnitAttribute class from a JSON object.
public LinearUnitAttribute(System.Text.Json.Nodes.JsonObject jsonObject);jsonObject System.Text.Json.Nodes.JsonObject
The System.Text.Json.Nodes.JsonObject containing the unit configuration.
Gets the additive offset used in the linear conversion calculation.
public double Offset { get; }Creates a clone of the current linear unit attribute.
public override DiGi.Core.Interfaces.ISerializableObject? Clone();Implements Clone()
DiGi.Core.Interfaces.ISerializableObject
A new instance of LinearUnitAttribute as an DiGi.Core.Interfaces.ISerializableObject.
Converts a value from the base unit to the target linear unit.
public override double From(double value);value System.Double
The value in the base unit.
System.Double
The converted value after applying the factor and offset.
Converts a value from the target linear unit back to the base unit.
public override double To(double value);value System.Double
The value in the target linear unit.
System.Double
The converted value after removing the offset and dividing by the factor.
Represents a measurement unit associated with an enumeration value, providing access to its attributes and conversion capabilities.
public class Unit : DiGi.Core.Classes.SerializableObject, DiGi.Core.Interfaces.INamedObject, DiGi.Core.Interfaces.IObjectInheritance System.Object → DiGi.Core.Classes.Object → DiGi.Core.Classes.SerializableObject → Unit
Implements DiGi.Core.Interfaces.INamedObject, DiGi.Core.Interfaces.IObject
Initializes a new instance of the Unit class with the specified enumeration value.
public Unit(System.Enum @enum);enum System.Enum
The enumeration value representing the unit.
Gets the category attribute associated with this unit.
public DiGi.Unit.Classes.CategoryAttribute? CategoryAttribute { get; }Gets the underlying enumeration value of this unit.
public System.Enum Enum { get; }Gets the name of the unit as defined in its attributes.
public string? Name { get; }Implements Name
Gets the symbol of the unit as defined in its attributes.
public string? Symbol { get; }Gets the unit attribute containing metadata and conversion logic for this unit.
public DiGi.Unit.Classes.UnitAttribute? UnitAttribute { get; }Gets the category to which this unit belongs, or Undefined if not specified.
public DiGi.Unit.Enums.UnitCategory UnitCategory { get; }Converts a value from the unit's scale to its base representation.
public double From(double value);value System.Double
The value to convert.
System.Double
The converted value, or System.Double.NaN if the unit attribute is missing.
Attempts to retrieve the underlying enumeration value cast to a specific enum type.
public TEnum? GetEnum<TEnum>()
where TEnum : System.Enum;TEnum
The expected enumeration type.
TEnum
The enumeration value cast to TEnum, or default if the types do not match.
Determines whether the unit is valid by checking if both its category and unit attributes are present.
public bool IsValid();System.Boolean
True if the unit is valid; otherwise, false.
Converts a base value to the unit's scale.
public double To(double value);value System.Double
The value to convert.
System.Double
The converted value, or System.Double.NaN if the unit attribute is missing.
Attempts to extract the underlying enumeration value as a specific type.
public bool TryGetEnum<TEnum>(out TEnum? @enum)
where TEnum : System.Enum;TEnum
The expected enumeration type.
enum TEnum
When this method returns, contains the enumeration value if successful; otherwise, the default value of TEnum.
System.Boolean
True if the underlying enum is of type TEnum; otherwise, false.
Explicitly converts an enumeration value to a Unit instance.
public static DiGi.Unit.Classes.Unit? explicit operator DiGi.Unit.Classes.Unit?(System.Enum? @enum);enum System.Enum
The enumeration value to convert.
Unit
A new Unit instance, or null if the provided enum is null.
Explicitly converts a Unit instance to its underlying enumeration value.
public static System.Enum? explicit operator System.Enum?(DiGi.Unit.Classes.Unit unit);unit Unit
The unit instance to convert.
System.Enum
The underlying System.Enum value, or null if the unit is null.
Base abstract class for unit attributes, implementing DiGi.Core.Interfaces.ISerializableObject and DiGi.Core.Interfaces.INamedObject to provide standardization for units of measurement including serialization and conversion logic.
public abstract class UnitAttribute : System.Attribute, DiGi.Core.Interfaces.ISerializableObject, DiGi.Core.Interfaces.ICloneableObject<DiGi.Core.Interfaces.ISerializableObject>, DiGi.Core.Interfaces.ICloneableObject, DiGi.Core.Interfaces.IObject, DiGi.Core.Interfaces.INamedObjectInheritance System.Object → System.Attribute → UnitAttribute
Derived
↳ FactorUnitAttribute
Implements DiGi.Core.Interfaces.ISerializableObject, DiGi.Core.Interfaces.ICloneableObject<DiGi.Core.Interfaces.ISerializableObject>, DiGi.Core.Interfaces.ICloneableObject, DiGi.Core.Interfaces.IObject, DiGi.Core.Interfaces.INamedObject
Initializes a new instance of the UnitAttribute class by copying values from an existing UnitAttribute.
public UnitAttribute(DiGi.Unit.Classes.UnitAttribute unit);unit UnitAttribute
The source unit attribute to copy from.
Initializes a new instance of the UnitAttribute class with a specified name and symbol.
public UnitAttribute(string? name, string? symbol);name System.String
The descriptive name of the unit.
symbol System.String
The shorthand symbol representing the unit.
Initializes a new instance of the UnitAttribute class using data from a System.Text.Json.Nodes.JsonObject.
public UnitAttribute(System.Text.Json.Nodes.JsonObject jsonObject);jsonObject System.Text.Json.Nodes.JsonObject
The JSON object containing the unit attribute data.
Gets the name of the unit.
public string? Name { get; }Implements Name
Gets the symbol of the unit.
public string? Symbol { get; }Creates a clone of the current object.
public abstract DiGi.Core.Interfaces.ISerializableObject? Clone();Implements Clone()
DiGi.Core.Interfaces.ISerializableObject
A cloned instance as an DiGi.Core.Interfaces.ISerializableObject, or null if cloning fails.
Converts a value from this unit's scale to a base reference scale.
public abstract double From(double value);value System.Double
The numeric value to convert.
System.Double
The converted value in the base reference scale.
Populates the properties of this object from a System.Text.Json.Nodes.JsonObject using DiGi.Core.Modify.FromJsonObject(DiGi.Core.Interfaces.ISerializableObject,System.Text.Json.Nodes.JsonObject).
public bool FromJsonObject(System.Text.Json.Nodes.JsonObject? jsonObject);jsonObject System.Text.Json.Nodes.JsonObject
The JSON object to populate from.
Implements FromJsonObject(JsonObject)
System.Boolean
True if the object was successfully populated; otherwise, false.
Converts a value from a base reference scale to this unit's scale.
public abstract double To(double value);value System.Double
The numeric value in the base reference scale.
System.Double
The converted value in this unit's scale.
Converts this object into a System.Text.Json.Nodes.JsonObject using DiGi.Core.Convert.ToJson(DiGi.Core.Interfaces.ISerializableObject).
public System.Text.Json.Nodes.JsonObject? ToJsonObject();Implements ToJsonObject()
System.Text.Json.Nodes.JsonObject
A System.Text.Json.Nodes.JsonObject representation of the current instance.
Manages a collection of units, providing functionality to add, retrieve, and perform conversions between different unit types.
public class UnitManagerInheritance System.Object → UnitManager
Initializes a new instance of the UnitManager class.
public UnitManager();Adds a unit associated with the specified enum value to the manager.
public DiGi.Unit.Classes.Unit? Add(System.Enum? @enum);enum System.Enum
The enum value representing the unit.
Unit
The created or existing Unit object, or null if the enum is null or the unit is invalid.
Scans the specified assembly for all Enum types decorated with a CategoryAttribute and adds them to the manager.
public System.Collections.Generic.List<DiGi.Unit.Classes.Unit>? AddRange(System.Reflection.Assembly? assembly);assembly System.Reflection.Assembly
The assembly to scan for unit enums.
System.Collections.Generic.List<Unit>
A list of all successfully added Unit objects, or null if the assembly is null.
Adds all units defined within the specified Enum type to the manager.
public System.Collections.Generic.List<DiGi.Unit.Classes.Unit>? AddRange(System.Type? type);type System.Type
The Type of the enum containing the units.
System.Collections.Generic.List<Unit>
A list of successfully added Unit objects, or null if the type is null.
Converts a value from the specified unit to its base representation.
public double From(System.Enum? @enum, double value, bool update=true);enum System.Enum
The enum value representing the source unit.
value System.Double
The numeric value to convert.
update System.Boolean
Whether to automatically add the unit to the manager if it is not already present.
System.Double
The converted value, or double.NaN if the unit could not be retrieved.
Retrieves the category attribute associated with the specified unit enum.
public DiGi.Unit.Classes.CategoryAttribute? GetCategoryAttribute(System.Enum? @enum, bool update=true);enum System.Enum
The enum value representing the unit.
update System.Boolean
Whether to automatically add the unit to the manager if it is not already present.
CategoryAttribute
The CategoryAttribute associated with the unit, or null if the unit could not be retrieved.
Retrieves the Unit object associated with the specified enum value.
public DiGi.Unit.Classes.Unit? GetUnit(System.Enum? @enum, bool update=true);enum System.Enum
The enum value representing the unit.
update System.Boolean
Whether to automatically add the unit to the manager if it is not already present.
Unit
The Unit object, or null if the enum is null or the unit cannot be found/created.
Retrieves the unit attribute associated with the specified unit enum.
public DiGi.Unit.Classes.UnitAttribute? GetUnitAttribute(System.Enum? @enum, bool update=true);enum System.Enum
The enum value representing the unit.
update System.Boolean
Whether to automatically add the unit to the manager if it is not already present.
UnitAttribute
The UnitAttribute associated with the unit, or null if the unit could not be retrieved.
Converts a base representation value to the specified unit.
public double To(System.Enum? @enum, double value, bool update=true);enum System.Enum
The enum value representing the target unit.
value System.Double
The numeric value to convert.
update System.Boolean
Whether to automatically add the unit to the manager if it is not already present.
System.Double
The converted value, or double.NaN if the unit could not be retrieved.