當前位置: 首頁>>代碼示例>>C#>>正文


C# NameTable.Get方法代碼示例

本文整理匯總了C#中System.Xml.NameTable.Get方法的典型用法代碼示例。如果您正苦於以下問題:C# NameTable.Get方法的具體用法?C# NameTable.Get怎麽用?C# NameTable.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.NameTable的用法示例。


在下文中一共展示了NameTable.Get方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AtomizedString

        /// <summary>
        /// Creates a new AtomizedString object.
        /// </summary>
        /// <param name="str">The string.  May not be null.</param>
        /// <param name="nameTable">The <Typ>NameTable</Typ> that should contain <P>str</P>,
        /// although this is not enforced (see remarks.)</param>
        /// <remarks>
        /// In order for <Typ>AtomizedString</Typ> comparisons to work correctly, the <P>str</P>
        /// parameter must be contained in the <P>nameTable</P>.  For performance reasons, this
        /// is not checked at runtime, except in debug builds where it throws ArgumentException.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <P>str</P> or <P>nameTable</P> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// (debug build only) <P>nameTable</P> does not contain <P>str</P>.
        /// </exception>
        internal AtomizedString(string str, NameTable nameTable)
        {
            if (str == null) throw new ArgumentNullException("str");
            if (nameTable == null) throw new ArgumentNullException("nameTable");
            m_NameTable = nameTable;
            // although there is no real guarantee that str is in nameTable without
            // specifically checking, it's not worth it to do so (except in debug builds.)
#if DEBUG
            if (null == nameTable.Get(str)) throw new ArgumentException(Resources.WrongNameTable);
#endif
            m_String = str;
        }
開發者ID:supermuk,項目名稱:iudico,代碼行數:29,代碼來源:HtmlTextReader.cs

示例2: XmlTest5_NameTable

        public MFTestResults XmlTest5_NameTable()
        {
            /// <summary>
            /// Tests the NameTable class, which implements XmlNameTable
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                XmlReader testReader = XmlReader.Create(new testStream());

                NameTable testNT = new NameTable();
                object root = testNT.Add("root");
                object element1 = testNT.Add("TestElement1");
                testReader.Read();
                object localName = testReader.LocalName;
                if (!(localName == root))
                {
                    Log.Comment("1st reading, expected local name '" + root + "' but got '" + localName + "'");
                    testResult = false;
                }
                testReader.Read();
                localName = testReader.LocalName;
                if (!(localName == element1))
                {
                    Log.Comment("2nd reading, expected local name '" + element1 + "' but got '" + localName + "'");
                    testResult = false;
                }

                testNT.Add("test1");

                if (testNT.Get("test1").GetType() != Type.GetType("System.String"))
                    throw new Exception("Get(string) got wrong type");

                if (testNT.Get("test1") != "test1")
                    throw new Exception("Get(string) got wrong data");

                if (testNT.Get("test1".ToCharArray(), 0, 5).GetType() != Type.GetType("System.String"))
                    throw new Exception("Get(string) got wrong type");

                if (testNT.Get("test1".ToCharArray(), 0, 5) != "test1")
                    throw new Exception("Get(string) got wrong data");

                testNT.Add("test2".ToCharArray(), 0, 5);

                if (testNT.Get("test2").GetType() != Type.GetType("System.String"))
                    throw new Exception("Get(string) got wrong type");

                if (testNT.Get("test2") != "test2")
                    throw new Exception("Get(string) got wrong data");

                if (testNT.Get("test2".ToCharArray(), 0, 5).GetType() != Type.GetType("System.String"))
                    throw new Exception("Get(string) got wrong type");

                if (testNT.Get("test2".ToCharArray(), 0, 5) != "test2")
                    throw new Exception("Get(string) got wrong data");

            }
            catch (Exception e)
            {
                testResult = false;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
開發者ID:awakegod,項目名稱:NETMF-LPC,代碼行數:65,代碼來源:XmlTests.cs


注:本文中的System.Xml.NameTable.Get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。