コード例 #1
0
ファイル: CMLConverter.cs プロジェクト: austad/Version3
        /// <summary>
        /// gets the chemical element from the cmlElement CML
        /// </summary>
        /// <param name="cmlElement">XElement containing CML</param>
        /// <returns></returns>
        private ElementBase GetChemicalElement(XElement cmlElement, out string message)
        {
            message = "";
            XAttribute xa = cmlElement.Attribute("elementType");

            if (xa != null)
            {
                string symbol = xa.Value;

                //try to return a chemical element from the Periodic Table
                if (Globals.PeriodicTable.HasElement(symbol))
                {
                    return(Globals.PeriodicTable.Elements[symbol]);
                }

                //if that fails, see if it's a functional group
                // ReSharper disable once InconsistentNaming
                FunctionalGroup newFG;
                if (FunctionalGroups.TryParse(symbol, out newFG))
                {
                    return(newFG);
                }

                //if we got here then it went very wrong
                message = $"Unrecognised element '{symbol}' in {cmlElement}";
            }
            else
            {
                message = $"cml attribute 'elementType' missing from {cmlElement}";
            }

            return(null);
        }
コード例 #2
0
ファイル: CMLConverter.cs プロジェクト: zhangwenquan/Version3
        /// <summary>
        /// gets the chemical element from the cmlElement CML
        /// </summary>
        /// <param name="cmlElement">XElement containing CML</param>
        /// <returns></returns>
        private ElementBase GetChemicalElement(XElement cmlElement)
        {
            string symbol = cmlElement.Attribute("elementType").Value;

            //try to return a chemical element from the Periodic Table
            if (Globals.PeriodicTable.HasElement(symbol))
            {
                return(Globals.PeriodicTable.Elements[symbol]);
            }

            //if that fails, see if it's a functional group
            // ReSharper disable once InconsistentNaming
            FunctionalGroup newFG;

            if (FunctionalGroups.TryParse(symbol, out newFG))
            {
                return(newFG);
            }

            //if we got here then it went very wrong
            throw new ArgumentOutOfRangeException($"Unrecognised element '{symbol}'.");
        }