public bool TryBuild(out Volume result, VolumeUnit?defaultUnit = null) { number? cubicMetres = _cubicMetres; number? value = _value; VolumeUnit?unit = _unit ?? defaultUnit; if (cubicMetres.HasValue) { result = new Volume(cubicMetres.Value); if (unit.HasValue) { result = result.Convert(unit.Value); } return(true); } if (value.HasValue && unit.HasValue) { result = new Volume(value.Value, unit.Value); return(true); } result = default(Volume); return(false); }
public bool TryBuild(out Angle result, AngleUnit?defaultUnit = null) { number? turns = _turns; number? value = _value; AngleUnit?unit = _unit ?? defaultUnit; if (turns.HasValue) { result = new Angle(turns.Value); if (unit.HasValue) { result = result.Convert(unit.Value); } return(true); } if (value.HasValue && unit.HasValue) { result = new Angle(value.Value, unit.Value); return(true); } result = default(Angle); return(false); }
public bool TryBuild(out Power result, PowerUnit?defaultUnit = null) { number? watts = _watts; number? value = _value; PowerUnit?unit = _unit ?? defaultUnit; if (watts.HasValue) { result = new Power(watts.Value); if (unit.HasValue) { result = result.Convert(unit.Value); } return(true); } if (value.HasValue && unit.HasValue) { result = new Power(value.Value, unit.Value); return(true); } result = default(Power); return(false); }
public bool TryBuild(out Weight result, WeightUnit?defaultUnit = null) { number? kilograms = _kilograms; number? value = _value; WeightUnit?unit = _unit ?? defaultUnit; if (kilograms.HasValue) { result = new Weight(kilograms.Value); if (unit.HasValue) { result = result.Convert(unit.Value); } return(true); } if (value.HasValue && unit.HasValue) { result = new Weight(value.Value, unit.Value); return(true); } result = default(Weight); return(false); }
public bool TryBuild(out Speed result, SpeedUnit?defaultUnit = null) { number? metresPerSecond = _metresPerSecond; number? value = _value; SpeedUnit?unit = _unit ?? defaultUnit; if (metresPerSecond.HasValue) { result = new Speed(metresPerSecond.Value); if (unit.HasValue) { result = result.Convert(unit.Value); } return(true); } if (value.HasValue && unit.HasValue) { result = new Speed(value.Value, unit.Value); return(true); } result = default(Speed); return(false); }
public bool TryBuild(out Energy result, EnergyUnit?defaultUnit = null) { number? joules = _joules; number? value = _value; EnergyUnit?unit = _unit ?? defaultUnit; if (joules.HasValue) { result = new Energy(joules.Value); if (unit.HasValue) { result = result.Convert(unit.Value); } return(true); } if (value.HasValue && unit.HasValue) { result = new Energy(value.Value, unit.Value); return(true); } result = default(Energy); return(false); }
static YVALUE any_return(YVALUE v, int type, number?n = null, string s = null) { v.type = type; if (n != null) { v.o = v.n = (number)n; } if (s != null) { v.s = s; if (v.o == null) { v.o = v.s; } } if (type == YDEF.BOOL) { v.o = (bool)(s.ToUpper() == "TRUE"); } if (v.o == null) { v.o = type; } return(v); }
public bool TryBuild(out Time result) { number?totalSeconds = TotalSeconds; if (totalSeconds.HasValue) { result = new Time(totalSeconds.Value); return(true); } int? hours = Hours; int? minutes = Minutes; number?seconds = Seconds; bool? isNegative = IsNegative; if (hours.HasValue && minutes.HasValue && seconds.HasValue && isNegative.HasValue) { result = new Time( hours.Value, minutes.Value, seconds.Value, isNegative.Value); return(true); } result = default(Time); return(false); }
public AngleUnitBuilder(AngleUnit unit) { _name = unit.Name; _abbreviation = unit.Abbreviation; _symbol = unit.Symbol; _unitsPerTurn = unit.UnitsPerTurn; }
public bool TryBuild(out Area result, AreaUnit?defaultUnit = null) { number? squareMetres = _squareMetres; number? value = _value; AreaUnit?unit = _unit ?? defaultUnit; if (squareMetres.HasValue) { result = new Area(squareMetres.Value); if (unit.HasValue) { result = result.Convert(unit.Value); } return(true); } if (value.HasValue && unit.HasValue) { result = new Area(value.Value, unit.Value); return(true); } result = default(Area); return(false); }
public bool TryBuild(out Length result, LengthUnit?defaultUnit = null) { number? metres = _metres; number? value = _value; LengthUnit?unit = _unit ?? defaultUnit; if (metres.HasValue) { result = new Length(metres.Value); if (unit.HasValue) { result = result.Convert(unit.Value); } return(true); } if (value.HasValue && unit.HasValue) { result = new Length(value.Value, unit.Value); return(true); } result = default(Length); return(false); }
public override GeoCoordinate ReadJson(JsonReader reader, Type objectType, GeoCoordinate existingValue, bool hasExistingValue, JsonSerializer serializer) { number?latitude = null; number?longitude = null; if (reader.TokenType == JsonToken.StartObject) { while (reader.Read() && reader.TokenType != JsonToken.EndObject) { if (reader.TryReadPropertyAsNullable(nameof(GeoCoordinate.Latitude), serializer, e => e.ReadAsNumber(), out var latitudeValue)) { latitude = latitudeValue; } else if (reader.TryReadPropertyAsNullable(nameof(GeoCoordinate.Longitude), serializer, e => e.ReadAsNumber(), out var longitudeValue)) { longitude = longitudeValue; } } } if (latitude == null || longitude == null) { throw new InvalidOperationException($"Could not read {typeof(GeoCoordinate)} from JSON."); } return(new GeoCoordinate(latitude.Value, longitude.Value)); }
public bool TryBuild(out DegreeAngle result) { number?totalSeconds = TotalSeconds; if (totalSeconds.HasValue) { result = new DegreeAngle(totalSeconds.Value); return(true); } int? circles = Circles; int? degrees = Degrees; int? minutes = Minutes; number?seconds = Seconds; bool? isNegative = IsNegative; if (circles.HasValue && degrees.HasValue && minutes.HasValue && seconds.HasValue && isNegative.HasValue) { result = new DegreeAngle( circles.Value, degrees.Value, minutes.Value, seconds.Value, isNegative.Value); return(true); } result = default(DegreeAngle); return(false); }
private number EnsureValue() { if (!_value.HasValue) { _value = GetValue(JoulesPerKilogram, Unit); } return(_value.Value); }
private number EnsureValue() { if (!_value.HasValue) { _value = GetValue(SquareMetres, Unit); } return(_value.Value); }
private number EnsureValue() { if (!_value.HasValue) { _value = GetValue(Watts, Unit); } return(_value.Value); }
private number EnsureSeconds() { if (!_seconds.HasValue) { _seconds = Math.Abs(TotalSeconds % Constants.ArcsecondsPerArcminute); } return(_seconds.Value); }
private number EnsureValue() { if (!_value.HasValue) { _value = GetValue(MetresPerSecond, Unit); } return(_value.Value); }
public VolumeUnit(string name, string abbreviation, number valueInCubicMetres) { Assert.IsNotNullOrWhiteSpace(name, nameof(name)); Assert.IsNotNullOrWhiteSpace(abbreviation, nameof(abbreviation)); Assert.IsGreaterThan(valueInCubicMetres, Constants.Zero, nameof(valueInCubicMetres)); _name = name; _abbreviation = abbreviation; _valueInCubicMetres = valueInCubicMetres; }
public PowerUnit(string name, string abbreviation, number valueInWatts) { Assert.IsNotNullOrWhiteSpace(name, nameof(name)); Assert.IsNotNullOrWhiteSpace(abbreviation, nameof(abbreviation)); Assert.IsGreaterThan(valueInWatts, Constants.Zero, nameof(valueInWatts)); _name = name; _abbreviation = abbreviation; _valueInWatts = valueInWatts; }
public SpeedUnit(string name, string abbreviation, number valueInMetresPerSecond) { Assert.IsNotNullOrWhiteSpace(name, nameof(name)); Assert.IsNotNullOrWhiteSpace(abbreviation, nameof(abbreviation)); Assert.IsGreaterThan(valueInMetresPerSecond, Constants.Zero, nameof(valueInMetresPerSecond)); _name = name; _abbreviation = abbreviation; _valueInMetresPerSecond = valueInMetresPerSecond; }
public SpecificEnergyUnit(string name, string abbreviation, number valueInJoulesPerKilogram) { Assert.IsNotNullOrWhiteSpace(name, nameof(name)); Assert.IsNotNullOrWhiteSpace(abbreviation, nameof(abbreviation)); Assert.IsGreaterThan(valueInJoulesPerKilogram, Constants.Zero, nameof(valueInJoulesPerKilogram)); _name = name; _abbreviation = abbreviation; _valueInJoulesPerKilogram = valueInJoulesPerKilogram; }
public WeightUnit(string name, string abbreviation, number valueInKilograms) { Assert.IsNotNullOrWhiteSpace(name, nameof(name)); Assert.IsNotNullOrWhiteSpace(abbreviation, nameof(abbreviation)); Assert.IsGreaterThan(valueInKilograms, Constants.Zero, nameof(valueInKilograms)); _name = name; _abbreviation = abbreviation; _valueInKilograms = valueInKilograms; }
private Energy(number joules, number?value, EnergyUnit?unit, bool validate = true) { if (validate) { Assert.IsInRange(joules, MinJoules, MaxJoules, nameof(value)); } Joules = joules; _value = value; _unit = unit; }
private Power(number watts, number?value, PowerUnit?unit, bool validate = true) { if (validate) { Assert.IsInRange(watts, MinWatts, MaxWatts, nameof(value)); } Watts = watts; _value = value; _unit = unit; }
private Volume(number cubicMetres, number?value, VolumeUnit?unit, bool validate = true) { if (validate) { Assert.IsInRange(cubicMetres, MinCubicMetres, MaxCubicMetres, nameof(value)); } CubicMetres = cubicMetres; _value = value; _unit = unit; }
private Length(number metres, number?value, LengthUnit?unit, bool validate = true) { if (validate) { Assert.IsInRange(metres, MinMetres, MaxMetres, nameof(value)); } Metres = metres; _value = value; _unit = unit; }
private Area(number squareMetres, number?value, AreaUnit?unit, bool validate = true) { if (validate) { Assert.IsInRange(squareMetres, MinSquareMetres, MaxSquareMetres, nameof(value)); } SquareMetres = squareMetres; _value = value; _unit = unit; }
private SpecificEnergy(number joulesPerKilogram, number?value, SpecificEnergyUnit?unit, bool validate = true) { if (validate) { Assert.IsInRange(joulesPerKilogram, MinJoulesPerKilogram, MaxJoulesPerKilogram, nameof(value)); } JoulesPerKilogram = joulesPerKilogram; _value = value; _unit = unit; }
private Angle(number turns, number?value, AngleUnit?unit, bool validate = true) { if (validate) { Assert.IsInRange(turns, MinTurns, MaxTurns, nameof(value)); } Turns = turns; _value = value; _unit = unit; }