public static char GetTemperatureCode(this TemperatureUnits value) { FieldInfo field = value.GetType().GetField(value.ToString()); TemperatureCode attribute = Attribute.GetCustomAttribute(field, typeof(TemperatureCode)) as TemperatureCode; return(attribute == null ? 'C' : attribute.Code); }
//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"); } }