/// <summary> /// Converts a value from the source vocabulary item units to /// the base units of the vocabulary. /// </summary> /// /// <remarks> /// This method does not check the sign of the value. The caller /// is responsible for ensuring the input data value make sense for /// the input vocabulary item. /// </remarks> /// /// <param name="vocabularyItem">The vocabulary item of the data /// value to convert to base units.</param> /// /// <param name="value">The data value to convert to base units. /// </param> /// /// <returns>The converted data value in the base units for the /// vocabulary. /// </returns> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="vocabularyItem"/> parameter is <b>null</b>. /// </exception> /// /// <exception cref="NotSupportedException"> /// The <paramref name="vocabularyItem"/> parameter does not /// support conversions to base units. /// </exception> /// /// <exception cref="ConversionFailureException"> /// An unknown or unsupported conversion is encountered or /// an error occurs during the conversion to base units. /// </exception> /// public static double ConvertToBaseUnits( VocabularyItem vocabularyItem, double value) { Validator.ThrowIfArgumentNull(vocabularyItem, "vocabularyItem", "VocabularyItemNull"); if (vocabularyItem.InfoXml == null) { throw Validator.NotSupportedException("VocabularyItemConversionNotSupported"); } XPathNavigator nav = vocabularyItem.InfoXml.CreateNavigator(); try { nav = nav.SelectSingleNode("unit-conversions/base-unit-conversion"); } catch(Exception) { //this can occur if conversion xml is corrupted. We don't //want to expose xml parse issues here to the outside world //as recommended by the .NET documentation for //XPathNavigator throw new ConversionFailureException( ResourceRetriever.GetResourceString( "VocabularyItemConversionGeneralException")); } if (nav == null) { throw Validator.NotSupportedException("VocabularyItemConversionNotSupported"); } return DoConversion(nav, value); }
internal override void AddVocabularyItem(string key, VocabularyItem item) { base.AddVocabularyItem(key, item); _orderedItemsList.Add(item); }