public static Mass To(this Mass mass, MassUnits unit) { if (mass.Units == unit) { return(new Mass() { Value = mass.Value, Units = mass.Units }); } switch (unit) { case MassUnits.Gram: return(mass.ToGrams()); case MassUnits.Kilogram: return(mass.ToKilograms()); case MassUnits.EarthMass: return(mass.ToEarths()); case MassUnits.StellarMass: return(mass.ToStellarMasses()); default: throw new Exception("Unknown distance units"); } }
public void InitalizeTest() { Units.Instance.Clear(); Measures.Instance.Clear(); MassUnits.Initialize(); Assert.AreEqual("mass", Measures.Instance.Find(x => x.Name == "mass").Name); Assert.AreEqual("kilogramm", Units.Instance.Find(x => x.Name == "kilogramm").Name); }
public static CreateParcel CreateForShipment( decimal length, decimal width, decimal height, DistanceUnits distance_unit, decimal weight, MassUnits massUnit) { return(new CreateParcel { Length = length, Width = width, Height = height, DistanceUnit = distance_unit, Weight = weight, MassUnit = massUnit }); }
public Mass(MassUnits currentUnit) : base(currentUnit) { }
public Mass(double value, MassUnits units) { Value = value; Units = units; }
//Method for laoding units into combo boxes private void UnitsLoading(string SelectedOp) { try { if (units == null) { } else { units.Clear(); if (unitsMults == null) { } else { unitsMults.Clear(); } } units = new List <string>(); unitsMults = new List <string>(); switch (SelectedOp) { case "Length": { LengthUnits unit = new LengthUnits(); MetersMults mults = new MetersMults(); var units2 = Enum.GetValues(unit.GetType()); var multiples = Enum.GetValues(mults.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } foreach (var item in multiples) { unitsMults.Add(item.ToString()); } break; } case "Mass and Weight": { MassUnits unit = new MassUnits(); KilogMults mults = new KilogMults(); var multiples = Enum.GetValues(mults.GetType()); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } foreach (var item in multiples) { unitsMults.Add(item.ToString()); } break; } case "Power": { PowerUnits unit = new PowerUnits(); WattMults mults = new WattMults(); var multiples = Enum.GetValues(mults.GetType()); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } foreach (var item in multiples) { unitsMults.Add(item.ToString()); } break; } case "Pressure": { PressureUnits unit = new PressureUnits(); PascaMults mults = new PascaMults(); var multiples = Enum.GetValues(mults.GetType()); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } foreach (var item in multiples) { unitsMults.Add(item.ToString()); } break; } case "Energy": { EnergyUnits unit = new EnergyUnits(); JouleMults mults = new JouleMults(); var multiples = Enum.GetValues(mults.GetType()); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } foreach (var item in multiples) { unitsMults.Add(item.ToString()); } break; } case "Temperature": { TemperatureUnits unit = new TemperatureUnits(); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } unitsMults.Add("Temperature doesn't have Multiples\n Please choose other option"); break; } case "Volume": { VolumeUnits unit = new VolumeUnits(); M3Mults mults = new M3Mults(); var multiples = Enum.GetValues(mults.GetType()); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } foreach (var item in multiples) { unitsMults.Add(item.ToString()); } break; } case "Angle": { AngleUnits unit = new AngleUnits(); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } unitsMults.Add("Angle doesn't have Multiples\n Please choose other option"); break; } case "Area": { AreaUnits unit = new AreaUnits(); MetersqrMults mults = new MetersqrMults(); var multiples = Enum.GetValues(mults.GetType()); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } foreach (var item in multiples) { unitsMults.Add(item.ToString()); } break; } case "Speed": { SpeedUnits unit = new SpeedUnits(); MPSMults mults = new MPSMults(); var multiples = Enum.GetValues(mults.GetType()); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } foreach (var item in multiples) { unitsMults.Add(item.ToString()); } break; } case "Time": { TimeUnits unit = new TimeUnits(); var units2 = Enum.GetValues(unit.GetType()); foreach (var item in units2) { units.Add(item.ToString()); } unitsMults.Add("Time doesn't have Multiples\n Please choose other option"); break; } } Fromcombo.Items.Clear(); ToCombo.Items.Clear(); MultsFromcombo.Items.Clear(); MultsTocombo.Items.Clear(); foreach (var v in units) { ComboBoxItem boxItem = new ComboBoxItem(); boxItem.Background = new SolidColorBrush(Color.FromArgb(System.Convert.ToByte(255), System.Convert.ToByte(40), System.Convert.ToByte(40), System.Convert.ToByte(40))); boxItem.Foreground = Brushes.Beige; boxItem.Opacity = 0.8; boxItem.BorderThickness = new Thickness(0.0); boxItem.Content = v; Fromcombo.Items.Add(boxItem); } foreach (var v in units) { ComboBoxItem boxItem = new ComboBoxItem(); boxItem.Background = new SolidColorBrush(Color.FromArgb(System.Convert.ToByte(255), System.Convert.ToByte(40), System.Convert.ToByte(40), System.Convert.ToByte(40))); boxItem.Foreground = Brushes.Beige; boxItem.Opacity = 0.8; boxItem.BorderThickness = new Thickness(0.0); boxItem.Content = v; ToCombo.Items.Add(boxItem); } foreach (var v in unitsMults) { ComboBoxItem boxItem = new ComboBoxItem(); boxItem.Background = new SolidColorBrush(Color.FromArgb(System.Convert.ToByte(255), System.Convert.ToByte(40), System.Convert.ToByte(40), System.Convert.ToByte(40))); boxItem.Foreground = Brushes.Beige; boxItem.Opacity = 0.8; boxItem.BorderThickness = new Thickness(0.0); boxItem.Content = v; MultsFromcombo.Items.Add(boxItem); } foreach (var v in unitsMults) { ComboBoxItem boxItem = new ComboBoxItem(); boxItem.Background = new SolidColorBrush(Color.FromArgb(System.Convert.ToByte(255), System.Convert.ToByte(40), System.Convert.ToByte(40), System.Convert.ToByte(40))); boxItem.Foreground = Brushes.Beige; boxItem.Opacity = 0.8; boxItem.BorderThickness = new Thickness(0.0); boxItem.Content = v; MultsTocombo.Items.Add(boxItem); } Fromcombo.SelectedIndex = 0; ToCombo.SelectedIndex = 0; MultsFromcombo.SelectedIndex = 0; MultsTocombo.SelectedIndex = 0; SelectedFrom = Fromcombo.SelectedItem.ToString().Remove(0, 38); SelectedTo = ToCombo.SelectedItem.ToString().Remove(0, 38); SelMultsFrom = MultsFromcombo.SelectedItem.ToString().Remove(0, 38); SelMultsTo = MultsTocombo.SelectedItem.ToString().Remove(0, 38); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message + "\nPlease Retry", "Loading-Content-Error"); } }
public Mass(double value, MassUnits unit) { Units = unit; Value = value; }
public Mass(double value) { Units = MassUnits.Kilogram; Value = value; }