ApprenticeFoundryRulesAndUnits 8.1.0
See the version list below for details.
dotnet add package ApprenticeFoundryRulesAndUnits --version 8.1.0
NuGet\Install-Package ApprenticeFoundryRulesAndUnits -Version 8.1.0
<PackageReference Include="ApprenticeFoundryRulesAndUnits" Version="8.1.0" />
<PackageVersion Include="ApprenticeFoundryRulesAndUnits" Version="8.1.0" />
<PackageReference Include="ApprenticeFoundryRulesAndUnits" />
paket add ApprenticeFoundryRulesAndUnits --version 8.1.0
#r "nuget: ApprenticeFoundryRulesAndUnits, 8.1.0"
#:package ApprenticeFoundryRulesAndUnits@8.1.0
#addin nuget:?package=ApprenticeFoundryRulesAndUnits&version=8.1.0
#tool nuget:?package=ApprenticeFoundryRulesAndUnits&version=8.1.0
Foundry Rules and Units
Overview
FoundryRulesAndUnits is a comprehensive, modernized unit system library providing type-safe unit conversions, measurement operations, and full backward compatibility. This library supports 6 complete unit systems (SI, MKS, CGS, FPS, IPS, mmNs) with 39+ unit families and advanced features for engineering and scientific applications.
๐ Key Features
Modern Architecture
- Unified Unit System: Clean IUnitSystem interface handling all conversions (no singletons!)
- Type-Safe Conversions: Strongly-typed unit operations with compile-time safety
- 24+ Unit Types: Complete coverage from Length/Mass to specialized units like Frequency/Resistance
- Factory Methods: Intuitive construction with
Length.FromMeters(5.0)
,Temperature.FromCelsius(25)
- Full Operator Support: Natural arithmetic with
length1 + length2
,force * scalar
Unit Systems Supported
- SI (International System of Units)
- MKS (Meter-Kilogram-Second)
- CGS (Centimeter-Gram-Second)
- FPS (Foot-Pound-Second)
- IPS (Inch-Pound-Second)
- mmNs (Millimeter-Newton-Second)
39+ Unit Families
- Mechanical: Length, Mass, Force, Speed, Power, Area, Volume
- Thermal: Temperature, Pressure
- Electrical: Voltage, Current, Resistance, Capacitance
- Digital: DataStorage, DataFlow
- Scientific: Frequency, Time, Duration, Angle
- Specialized: Quantity, QuantityFlow, Percent, Dimensionless
๐ฆ Installation & Setup
NuGet Package
<PackageReference Include="ApprenticeFoundryRulesAndUnits" Version="8.0.0" />
Basic Setup
using FoundryRulesAndUnits.Units;
// Initialize the global unit system (do this once at app startup)
MeasuredValue.SetGlobalUnitSystem(UnitSystemType.SI); // or MKS, CGS, FPS, IPS, mmNs
// Alternatively, set it with a UnitSystem instance
var unitSystem = new UnitSystem(UnitSystemType.SI);
MeasuredValue.SetGlobalUnitSystem(unitSystem);
๐ก Quick Start Examples
Creating Measurements
// Factory methods (recommended)
var length = Length.FromMeters(5.0);
var temp = Temperature.FromCelsius(25.0);
var force = Force.FromNewtons(100.0);
// Constructor approach
var mass = new Mass(50.0, "kg");
var speed = new Speed(60.0, "mph");
Unit Conversions
var length = Length.FromMeters(5.0);
double feet = length.As("ft"); // Convert to feet
double inches = length.As("in"); // Convert to inches
double pixels = length.AsPixels(); // Special conversion for UI
Arithmetic Operations
var length1 = Length.FromMeters(10);
var length2 = Length.FromFeet(5);
var total = length1 + length2; // Addition
var difference = length1 - length2; // Subtraction
var scaled = length1 * 2.0; // Scalar multiplication
var ratio = length1 / length2; // Ratio (returns double)
Advanced Operations
// Create flow rates from quantities and time
var quantity = Quantity.FromEach(1000);
var time = Time.FromSeconds(60);
var flow = quantity / time; // QuantityFlow in "ea/s"
// Compare measurements
if (length1 > length2) {
Console.WriteLine("Length1 is longer");
}
๐๏ธ Architecture Overview
Modern Unit Classes (24/24 FULLY MODERNIZED) ๐
ALL unit classes now follow the clean, modern pattern:
โ Physical & Mechanical Units:
Length
,Mass
,Temperature
,Volume
,Force
Speed
,Power
,Area
,Time
,Duration
Distance
,Frequency
โ Electrical Units:
Voltage
,Resistance
,Current
,Capacitance
โ Digital & Computing Units:
DataStorage
,DataFlow
โ Specialized Units:
Quantity
,QuantityFlow
,Percent
,Heading
,Dimensionless
๐ ALL CLASSES FEATURE:
- Factory methods (
FromMeters()
,FromVolts()
, etc.) - Enhanced operators (+, -, *, /, >, <, etc.)
- JSON serialization support
- Full backward compatibility
Unit System Management
// Global unit system manages all conversions (clean, no singletons!)
var globalSystem = MeasuredValue.GlobalSystem;
// Switch unit systems at runtime
globalSystem.Apply(UnitSystemType.FPS); // Switch to Imperial
var converted = globalSystem.Convert(100, "m", "ft"); // 328.084 feet
// Or change globally for all measurements
MeasuredValue.SetGlobalUnitSystem(UnitSystemType.FPS);
// Validation
bool isValid = globalSystem.IsValidUnit("mph"); // true
var units = globalSystem.GetUnitsForFamily(UnitFamilyName.Length); // ["m", "cm", "km", ...]
๐ Backward Compatibility
Legacy Support Classes
For existing codebases, we provide full compatibility:
// Legacy UnitSystem class (now contains all functionality directly)
var unitSystem = new UnitSystem(UnitSystemType.MKS);
unitSystem.Apply(UnitSystemType.SI);
var categories = unitSystem.Categories();
// Legacy extension methods
var family = UnitCategoryExtensions.GetUnitFamily("kg"); // UnitFamilyName.Mass
bool known = UnitCategoryExtensions.IsKnownUnit("mph"); // true
// Legacy Length methods
var length = new Length(100, "m");
var category = Length.Category(); // UnitCategory (marked obsolete)
double pixels = length.AsPixels(); // UI conversion
๐ Migration Guide
From Legacy to Modern
Old Pattern:
// Legacy approach
var length = new Length(5.0, "m");
var convertedValue = length.As("ft");
New Pattern:
// Modern approach
var length = Length.FromMeters(5.0); // Factory method
var convertedValue = length.As("ft"); // Same conversion API
Key Benefits of Modern Classes
- Factory Methods:
Length.FromMeters()
vsnew Length(value, "m")
- Enhanced Operators: Full arithmetic support including scalar operations
- Better Performance: Direct integration with global unit system
- JSON Serialization: Built-in JSON converter support
- Cleaner Code: No singleton dependencies, clean architecture!
๐งช Testing & Validation
Build Status
- โ FoundryRulesAndUnits: Builds successfully (3 warnings)
- โ FoundryMentorModeler: Builds successfully (3 warnings)
- โ All Tests Passing: Legacy compatibility maintained
Validation Examples
// Unit system validation
var globalSystem = MeasuredValue.GlobalSystem;
Debug.Assert(globalSystem.IsValidUnit("kg"));
Debug.Assert(globalSystem.Convert(1000, "g", "kg") == 1.0);
// Measurement validation
var length = Length.FromKilometers(1.0);
Debug.Assert(Math.Abs(length.As("m") - 1000.0) < 0.001);
๐ Project Structure
FoundryRulesAndUnits/
โโโ UnitSystem/
โ โโโ MeasuredValue.cs # Base class with global unit system
โ โโโ UnitSystem.cs # Complete IUnitSystem implementation
โ โโโ UnitCategory.cs # Legacy compatibility (+ enum)
โ โโโ Specifications/ # Unit system definitions
โ โ โโโ IUnitSystemSpecification.cs
โ โ โโโ SISpecification.cs # SI unit definitions
โ โ โโโ MKSSpecification.cs # MKS unit definitions
โ โ โโโ [Other system specs...]
โ โโโ UnitTypes/ # Individual unit classes
โ โโโ Length.cs # โ
Modernized
โ โโโ Mass.cs # โ
Modernized
โ โโโ Temperature.cs # โ
Modernized
โ โโโ Force.cs # โ
Modernized
โ โโโ [24+ other unit types...]
โโโ Extensions/
โ โโโ UnitCategoryExtensions.cs # Legacy compatibility helpers
โ โโโ [Other utility extensions...]
โโโ DataModels/ # Supporting data structures
๐ค Contributing
Adding New Unit Types
Follow the modernized pattern:
[System.Serializable]
[JsonConverter(typeof(MyUnitJsonConverter))]
public class MyUnit : MeasuredValue
{
public MyUnit() : base(UnitFamilyName.MyFamily) { }
public MyUnit(double value, string? units = null) : base(UnitFamilyName.MyFamily)
{
Init(value, units);
}
// Factory methods
public static MyUnit FromBaseUnit(double value) => new(value, "base");
// Operators
public static MyUnit operator +(MyUnit left, MyUnit right) =>
new(left.Value() + right.Value(), left.Internal());
}
Extending Unit Systems
Add new specifications implementing IUnitSystemSpecification
:
public class MyCustomSpecification : IUnitSystemSpecification
{
public string SystemName => "MySystem";
// Implement interface methods...
}
๐ License
MIT License - See LICENSE file for details.
๐ข Authors
- Stephen Strong - Apprentice Foundry
- Company: Stephen Strong
- Project URL: https://apprenticefoundry.github.io/
๐ Related Projects
- FoundryMentorModeler: Advanced modeling toolkit using this unit system
- TRISoC Dashboard: Digital twin dashboard with unit system integration
Version: 8.0.0 | Target: .NET 9.0 | Updated: September 2025
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- System.Text.Json (>= 9.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ApprenticeFoundryRulesAndUnits:
Package | Downloads |
---|---|
ApprenticeFoundryBlazor
A comprehensive C# / Blazor diagramming library that combines 2D and 3D visualization capabilities. Supports .NET 9, includes advanced layout algorithms, glued connections, multi-page diagrams, and seamless 2D/3D integration. |
|
ApprenticeFoundryBlazorThreeJS
3D graphics for blazor applications |
|
ApprenticeFoundryMessageLibrary
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
9.0.0 | 0 | 9/23/2025 |
8.1.0 | 46 | 9/22/2025 |
7.3.0 | 162 | 8/11/2025 |
7.2.0 | 144 | 8/10/2025 |
7.1.0 | 98 | 8/9/2025 |
7.0.0 | 126 | 8/9/2025 |
6.1.0 | 103 | 7/11/2025 |
5.3.0 | 581 | 2/7/2025 |
5.2.0 | 218 | 1/28/2025 |
5.1.0 | 220 | 1/20/2025 |
5.0.2 | 120 | 1/11/2025 |
5.0.1 | 146 | 1/1/2025 |
5.0.0 | 143 | 1/1/2025 |
4.4.0 | 249 | 11/17/2024 |
4.3.0 | 709 | 9/11/2024 |
4.2.0 | 155 | 9/11/2024 |
4.1.0 | 146 | 9/10/2024 |
4.0.0 | 375 | 8/27/2024 |
3.7.0 | 392 | 8/20/2024 |
3.6.0 | 221 | 8/13/2024 |
3.5.0 | 175 | 8/10/2024 |
3.4.0 | 447 | 7/18/2024 |
3.3.0 | 145 | 7/16/2024 |
3.2.0 | 395 | 6/8/2024 |
3.1.0 | 594 | 5/6/2024 |
3.0.0 | 323 | 3/12/2024 |
2.0.2 | 250 | 1/25/2024 |
2.0.1 | 461 | 12/11/2023 |
2.0.0 | 460 | 11/26/2023 |
1.3.4 | 1,302 | 11/17/2023 |
1.3.3 | 154 | 11/16/2023 |
1.3.2 | 189 | 11/16/2023 |
1.3.1 | 215 | 11/12/2023 |
1.3.0 | 156 | 11/12/2023 |
1.2.1 | 188 | 11/12/2023 |
1.2.0 | 156 | 11/12/2023 |
1.1.0 | 148 | 11/4/2023 |
1.0.9 | 979 | 10/31/2023 |
1.0.8 | 199 | 10/30/2023 |
1.0.7 | 156 | 10/29/2023 |
1.0.6 | 201 | 10/21/2023 |
1.0.5 | 583 | 10/1/2023 |