Comments (4)
22122bd - Just relaxed the restrictions on some methods from Internal to public in order for users to better create their customs units
from engineeringunits.
I have started on a Wiki post about creating custom units.
Could you try it out and see if you can get it to work?
https://github.com/MadsKirkFoged/EngineeringUnits/wiki/Costume-units
from engineeringunits.
Works for me. Obviously the 2nd method doesn't give you the getters and setter methods which I personally prefer using.
These can be added as extensions as well but it is more work. Note also that you have to use two different namespaces if you want to use the same name for the unit enum and the getter, as is the case for regular units..
Using your example, this would look like:
public static class LengthCostUnitExtensions
{
// New unit
public static readonly LengthCostUnit EuroPerMeter = new LengthCostUnit(CostUnit.Euro, LengthUnit.Meter);
}
public static class LengthCostExtensions
{
// New getter
public static double EuroPerMeter(this LengthCost lengthCost) => lengthCost.As(LengthCostUnitExtensions.EuroPerMeter);
// New setter method
public static LengthCost FromEuroPerMeter(double? EuroPerMeter)
{
if (!EuroPerMeter.HasValue)
{
return null;
}
return new LengthCost(EuroPerMeter.Value, LengthCostUnitExtensions.EuroPerMeter);
}
}
It's not ideal since the getter is now a method instead of a property and the setter has to be called with the extensions namespace:
// ideally LengthCost lc = LengthCost.FromEuroPerMeter(30.0);
LengthCost lc = LengthCostExtensions.FromEuroPerMeter(30.0);
// ideally Console.WriteLine(lc.EuroPerMeter);
Console.WriteLine(lc.EuroPerMeter());
from engineeringunits.
Btw, was "Costume Units" in the wiki (both title and url) intended or a typo?
from engineeringunits.
Related Issues (20)
- Optimize for performance HOT 6
- Temperature conversion doesn't work HOT 4
- bug: Race Condition when accessing the UnitSystem.CacheMultiply and UnitSystem.CacheDivide dictionaries HOT 4
- Specific Heat HOT 3
- Molar Specific Heat Units Don't Match HOT 5
- Help convertint class from UnitsNet HOT 4
- New unit: Molar flow HOT 4
- Add ideal gas constant HOT 2
- Thread safety and Possible race conditions HOT 4
- New unit: specific volume HOT 1
- New unit: volumetric heat transfer coefficient HOT 1
- Null comparison with operator throws NullReferenceException HOT 1
- New Unit JERK HOT 1
- Unexpected / inconsistent behavior of BaseUnit.GetValueAs() for mass units (potential bug) HOT 1
- Add support for NaN HOT 6
- .Minimum and .Maximum are mixed up HOT 8
- Add unary minus operator? HOT 3
- Adding Cost/Currency/Price HOT 6
- Support for specific thermal resistance / thermal resistivity (K⋅m/W) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from engineeringunits.