当前位置: 首页>>代码示例>>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;未经允许,请勿转载。