ApprenticeFoundryRulesAndUnits 9.0.0
See the version list below for details.
dotnet add package ApprenticeFoundryRulesAndUnits --version 9.0.0
NuGet\Install-Package ApprenticeFoundryRulesAndUnits -Version 9.0.0
<PackageReference Include="ApprenticeFoundryRulesAndUnits" Version="9.0.0" />
<PackageVersion Include="ApprenticeFoundryRulesAndUnits" Version="9.0.0" />
<PackageReference Include="ApprenticeFoundryRulesAndUnits" />
paket add ApprenticeFoundryRulesAndUnits --version 9.0.0
#r "nuget: ApprenticeFoundryRulesAndUnits, 9.0.0"
#:package ApprenticeFoundryRulesAndUnits@9.0.0
#addin nuget:?package=ApprenticeFoundryRulesAndUnits&version=9.0.0
#tool nuget:?package=ApprenticeFoundryRulesAndUnits&version=9.0.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,ForceSpeed,Power,Area,Time,DurationDistance,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 (5)
Showing the top 5 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 |
|
|
ApprenticeFoundryMentorModeler
Package Description |
|
|
ApprenticeFoundryWorldsAndDrawings
Unified 2D and 3D drawing and graphics library for Blazor applications |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.10.0 | 133 | 12/28/2025 |
| 10.9.0 | 211 | 12/21/2025 |
| 10.8.2 | 289 | 12/4/2025 |
| 10.8.1 | 142 | 11/29/2025 |
| 10.7.0 | 197 | 11/23/2025 |
| 10.6.0 | 272 | 11/16/2025 |
| 10.5.0 | 188 | 11/15/2025 |
| 10.4.1 | 340 | 11/12/2025 |
| 10.4.0 | 230 | 11/6/2025 |
| 10.3.0 | 267 | 11/2/2025 |
| 10.2.0 | 212 | 11/2/2025 |
| 10.1.0 | 236 | 10/30/2025 |
| 10.0.0 | 232 | 10/29/2025 |
| 9.3.0 | 147 | 10/25/2025 |
| 9.2.0 | 243 | 10/22/2025 |
| 9.1.0 | 273 | 10/14/2025 |
| 9.0.0 | 341 | 9/23/2025 |
| 8.1.0 | 355 | 9/22/2025 |
| 7.3.0 | 244 | 8/11/2025 |
| 7.2.0 | 334 | 8/10/2025 |