Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/criteria-for-adding-quantities-and-units.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Criteria for adding quantities and units

Related wiki page: https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit#a-quantity-is-a-good-fit-to-add-if-it
See also: [Docs/adding-a-new-unit.md](../Docs/adding-a-new-unit.md#great-but-before-you-start) for the full contributor guide.

To avoid bloating the library, we want to ensure quantities and units are widely used and well defined.
Avoid little used units that are obscure or too domain specific.
Expand Down
12 changes: 11 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ The project uses a sophisticated code generation system:

### Adding or Modifying Units
1. Edit or create JSON file in `Common/UnitDefinitions/`
2. Follow conversion function guidelines:
2. Follow conversion function guidelines in [Docs/adding-a-new-unit.md](Docs/adding-a-new-unit.md):
- Use multiplication for `FromUnitToBaseFunc`
- Use division for `FromBaseToUnitFunc`
- Prefer scientific notation (1e3, 1e-5)
- Use exact constituent constants instead of pre-computed decimals
3. Run `generate-code.bat`
4. Add tests if needed

Expand Down Expand Up @@ -118,6 +119,15 @@ The project uses a sophisticated code generation system:
- Execute: `dotnet run -c Release --project UnitsNet.Benchmark`
- Results saved to `Artifacts/` folder

## Documentation

All contributor and user documentation lives in [Docs/](Docs/README.md), including:
- [Adding a New Unit](Docs/adding-a-new-unit.md) — step-by-step guide with JSON schema conventions
- [Adding Operator Overloads](Docs/adding-operator-overloads.md)
- [Precision](Docs/precision.md) — conversion precision and test value guidelines
- [Serialization](Docs/serialization.md), [String Formatting](Docs/string-formatting.md), [Saving to Database](Docs/saving-to-database.md)
- [Upgrade Guides](Docs/README.md#upgrade-guides) for major version migrations

## Pull request reviews

### Adding new quantities or units
Expand Down
37 changes: 11 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Contributing to Units.NET
# Contributing to Units.NET

Guidelines for contributing to the repo.
<!--markdownlint-disable MD026 -->
## We want your help and we are friendly to first-time contributors!

Adding a new unit or a new quantity is easy! We have detailed the steps here and if you need any assistance we are happy to help!
Adding a new unit or a new quantity is easy! See the detailed step-by-step guide:

https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit
**[Adding a New Quantity or Unit](Docs/adding-a-new-unit.md)**

We also want the person with the idea, suggestion or bug report to implement the change in code and get a sense of ownership for that piece of the library.
This is to help grow the number of people that can contribute to the project and after someone new lands that first PR we often see more PRs from that person later.
Expand All @@ -24,19 +24,11 @@ This is to help grow the number of people that can contribute to the project and
* Test method: `<method>_<condition>_<result>` (`Parse_AmbiguousUnits_ThrowsException`)
* If there are many tests for a single method, you can wrap those in an inner class named the same as the method and then you can skip that part of the test method names

## Unit definitions (.JSON)
## Unit Definitions (.JSON)

For a fairly complete summary of the unit definition JSON schema, see [Meter of Length](https://github.com/angularsen/UnitsNet/blob/master/Common/UnitDefinitions/Length.json). It has prefix units and multiple cultures.

### Conversion functions

Converting from unit A to B is achieved by first converting from unit A to the base unit, then from the base unit to unit B. To achieve this, each unit defines two conversion functions.

* Prefer multiplication for `FromUnitToBaseFunc` (`{x} * 2.54e-2` for `Inch` to `Meter`)
* Prefer division for `FromBaseToUnitFunc` (`{x} / 2.54e-2` for `Meter` to `Inch`)
* Prefer scientific notation `1e3` and `1e-5` instead of `1000` and `0.00001`
* Prefer a constant if the conversion factor is finite (`{x} * 2.54e-2` for `Inch`)
* Prefer a calculation if the conversion factor is infinite (`({x} / 72.27)*2.54e-2` for `PrinterPoint`)
For detailed conventions on conversion functions, abbreviations, base dimensions, and more, see [Adding a New Unit](Docs/adding-a-new-unit.md#1-add-or-modify-json-file-for-a-quantity-class).

### Units

Expand All @@ -46,17 +38,10 @@ Generally we try to name the units as what is the most widely used.

**Note:** We should really consider switching variant prefix to suffix, since that plays better with kilo, mega etc.. Currently we have units named `KilousGallon` and `KiloimperialGallon`, these would be better named `KilogallonUs` and `KilogallonImperial`.

### Unit abbreviations

A unit can have multiple abbreviations per culture/language, the first one is used by `ToString()` while all of them are used by `Parse()`.
## More Documentation

* Prefer the most widely used abbreviation in the domain, but try to adapt to our conventions
* Add other popular variants to be able to parse those too, but take care to avoid abbreviation conflicts of units of the same quantity
* Use superscript (`cm²`, `m³`) instead of `cm^2`, `m^3`
* Use `∆` for delta (not `▲`)
* Use `·` for products (`N·m` instead of `Nm`, `N*m` or `N.m`)
* Prefer `/` over `⁻¹`, such as `km/h` and `J/(mol·K)`
* Use `h` for hours, `min` for minutes and `s` for seconds (`m` is ambiguous with meters)
* Use suffixes to distinguish variants of similar units, such as `gal (U.S.)` vs `gal (imp.)` for gallons
* `(U.S.)` for United States
* `(imp.)` for imperial / British units
See [Docs/](Docs/README.md) for the full documentation index, including:
- [Precision](Docs/precision.md) — conversion precision and test guidelines
- [Adding Operator Overloads](Docs/adding-operator-overloads.md)
- [Serialization](Docs/serialization.md)
- [Upgrade Guides](Docs/README.md#upgrade-guides)
35 changes: 35 additions & 0 deletions Docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Units.NET Documentation

## Contributing

- [Adding a New Quantity or Unit](adding-a-new-unit.md) — step-by-step guide for adding quantities and units
- [Adding Operator Overloads](adding-operator-overloads.md) — how to add strongly-typed arithmetic operators
- [Precision](precision.md) — how conversions work and their precision limits

## Using the Library

- [String Formatting](string-formatting.md) — format specifiers and culture-aware output
- [Serialization](serialization.md) — JSON, XML, and custom DTO serialization
- [Saving to Database](saving-to-database.md) — strategies for persisting quantities
- [Extending with Custom Units](extending-with-custom-units.md) — adding runtime custom quantities

## Platform Support

- [.NET nanoFramework](nanoframework.md) — embedded device support
- [Experimental: Generic Math](experimental-generic-math.md) — .NET 7+ generic math interfaces

## Upgrade Guides

- [Upgrading from 3.x to 4.x](upgrading-from-3.x-to-4.x.md)
- [Upgrading from 4.x to 5.x](upgrading-from-4.x-to-5.x.md)
- [Upgrading from 5.x to 6.x](upgrading-from-5.x-to-6.x.md)

## Collaborator Guides

- [Issues and Pull Requests](collaborators/issues-and-pull-requests.md) — guidelines for reviewing and merging
- [Releasing NuGet Packages](collaborators/releasing-nugets.md) — how to publish new versions
- [Regenerate NuGet API Key](collaborators/regenerate-nuget-api-key.md) — annual key rotation

## Other

- [Top Dependencies](top-dependencies.md) — notable projects using UnitsNet
Loading
Loading