//TODO: Change to ReadOnlyDictionary when .Net 4.0 is available Dictionary <string, Symbol> GetAllIndividualSymbols() { var unitDict = new Dictionary <string, Symbol> (); var unitPro = new UnitProvider(); var query = from s in unitPro.UnitTypes select s; foreach (var itm in query) { UnitType ut = itm.Value; foreach (var un in ut.Units) { Unit unit = un; foreach (var us in unit.Symbols) { if (!unitDict.ContainsKey(us.Value)) { unitDict.Add(us.Value, us); } } } } return(unitDict); }
// Given the name of a unit, searches for the unit group it belongs to. UnitType GetUnitType(string unitName) { if (string.IsNullOrEmpty(unitName)) { throw new ArgumentException("unitName must have a value"); } #if !NETSTANDARD1_4 Contract.EndContractBlock(); #endif //Does the unit even exist? if (this._UnitDictionary.ContainsKey(unitName) == false) { return(null); } else { //Iterate through every group var unitPro = new UnitProvider(); foreach (var ut in unitPro.UnitTypes) { if (ut.Value.Units.Contains(new Unit { Name = unitName })) { return(ut.Value); } } return(null); } }
// Constructor, sets up the unit converter. public UnitConverter() { //Set up the tables we need var unitPro = new UnitProvider (); _SymbolDictionary = unitPro.Symbols; _IndividualSymbolDictionary = unitPro.IndividualSymbols; _UnitDictionary = unitPro.Units; _UnitTypeDictionary = unitPro.UnitTypes; }
// Constructor, sets up the unit converter. public UnitConverter() { //Set up the tables we need var unitPro = new UnitProvider(); _SymbolDictionary = unitPro.Symbols; _IndividualSymbolDictionary = unitPro.IndividualSymbols; _UnitDictionary = unitPro.Units; _UnitTypeDictionary = unitPro.UnitTypes; }
//TODO: Change to ReadOnlyDictionary when .Net 4.0 is available Dictionary <string, Unit> GetAllUnits() { var unitDict = new Dictionary <string, Unit> (); var unitPro = new UnitProvider(); var query = from s in unitPro.UnitTypes select s; foreach (var itm in query) { UnitType ut = itm.Value; foreach (var un in ut.Units) { if (!unitDict.ContainsKey(un.Name)) { unitDict.Add(un.Name, un); } } //Units "Celsius" } //UnitTypes "Temperature" return(unitDict); }
//TODO: Change to ReadOnlyDictionary when .Net 4.0 is available Dictionary<string, Unit> GetAllUnits() { var unitDict = new Dictionary<string, Unit> (); var unitPro = new UnitProvider (); var query = from s in unitPro.UnitTypes select s; foreach (var itm in query) { UnitType ut = itm.Value; foreach (var un in ut.Units) { if (!unitDict.ContainsKey (un.Name)) { unitDict.Add (un.Name, un); } } //Units "Celsius" } //UnitTypes "Temperature" return unitDict; }
//TODO: Change to ReadOnlyDictionary when .Net 4.0 is available Dictionary<string, Symbol> GetAllIndividualSymbols() { var unitDict = new Dictionary<string, Symbol> (); var unitPro = new UnitProvider (); var query = from s in unitPro.UnitTypes select s; foreach (var itm in query) { UnitType ut = itm.Value; foreach (var un in ut.Units) { Unit unit = un; foreach (var us in unit.Symbols) { if (!unitDict.ContainsKey (us.Value)) { unitDict.Add (us.Value, us); } } } } return unitDict; }
// Given the name of a unit, searches for the unit group it belongs to. UnitType GetUnitType(string unitName) { if (string.IsNullOrEmpty (unitName)) { throw new ArgumentException ("unitName must have a value"); } Contract.EndContractBlock (); //Does the unit even exist? if (this._UnitDictionary.ContainsKey (unitName) == false) { return null; } else { //Iterate through every group var unitPro = new UnitProvider (); foreach (var ut in unitPro.UnitTypes) { if (ut.Value.Units.Contains (new Unit { Name = unitName })) { return ut.Value; } } return null; } }