• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Linq.XComment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Xml.Linq.XComment的典型用法代码示例。如果您正苦于以下问题:C# XComment类的具体用法?C# XComment怎么用?C# XComment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



XComment类属于System.Xml.Linq命名空间,在下文中一共展示了XComment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Console.Write("\n  Create XML file using XDocument");
              Console.Write("\n =================================\n");

              XDocument xml = new XDocument();
              xml.Declaration = new XDeclaration("1.0", "utf-8", "yes");
             /*
              *  It is a quirk of the XDocument class that the XML declaration,
              *  a valid processing instruction element, cannot be added to the
              *  XDocument's element collection.  Instead, it must be assigned
              *  to the document's Declaration property.
              */
              XComment comment = new XComment("Demonstration XML");
              xml.Add(comment);

              XElement root = new XElement("root");
              xml.Add(root);
              XElement child1 = new XElement("child1", "child1 content");
              XElement child2 = new XElement("child2");
              XElement grandchild21 = new XElement("grandchild21", "content of grandchild21");
              child2.Add(grandchild21);
              root.Add(child1);
              root.Add(child2);

              Console.Write("\n{0}\n", xml.Declaration);
              Console.Write(xml.ToString());
              Console.Write("\n\n");
        }
开发者ID:DhivyaNarayanan,项目名称:CodeAnalyzer,代码行数:29,代码来源:XDocument-Create-XML.cs


示例2: DestinationProjXml

        internal DestinationProjXml(string destProj)
        {
            DestProjAbsolutePath = PathMaker.MakeAbsolutePathFromPossibleRelativePathOrDieTrying(null, destProj);
            DestProjDirectory = Path.GetDirectoryName(DestProjAbsolutePath) ?? "";

            try
            {
                DestProjXdoc = XDocument.Load(DestProjAbsolutePath);
                RootXelement = DestProjXdoc.Element(Settings.MSBuild + "Project");
                ItemGroups = RootXelement?.Elements(Settings.MSBuild + "ItemGroup").ToList();
            }
            catch (Exception e)
            {
                App.Crash(e, "Crash: DestProjXml CTOR loading destination XML from " + DestProjAbsolutePath);
            }

            if (RootXelement == null)
                App.Crash("Crash: No MSBuild Namespace in " + DestProjAbsolutePath);

            StartPlaceHolder = FindCommentOrCrashIfDuplicatesFound(Settings.StartPlaceholderComment);
            EndPlaceHolder = FindCommentOrCrashIfDuplicatesFound(Settings.EndPlaceholderComment);

            if (StartPlaceHolder == null && RootXelement != null)
            {
                XElement lastItemGroup = ItemGroups?.Last();
                lastItemGroup?.AddAfterSelf(new XComment(Settings.EndPlaceholderComment));
                lastItemGroup?.AddAfterSelf(new XComment(Settings.StartPlaceholderComment));
                StartPlaceHolder = FindCommentOrCrashIfDuplicatesFound(Settings.StartPlaceholderComment);
                EndPlaceHolder = FindCommentOrCrashIfDuplicatesFound(Settings.EndPlaceholderComment);
            }

            OldLinkedXml = ReadLinkedXml();
            Keepers = new List<XElement>();
        }
开发者ID:CADbloke,项目名称:CodeLinker,代码行数:34,代码来源:DestinationProjXml.cs


示例3: CreateCommentSimple

        public void CreateCommentSimple()
        {
            Assert.Throws<ArgumentNullException>(() => new XComment((string)null));

            XComment c = new XComment("foo");
            Assert.Equal("foo", c.Value);
            Assert.Null(c.Parent);
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:8,代码来源:SDMComment.cs


示例4: XComment

 public XComment(XComment other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     this.value = other.value;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:XComment.cs


示例5: DeepEquals

        /// <summary>
        /// Compares two comments using the indicated comparison options.
        /// </summary>
        /// <param name="c1">The first comment to compare.</param>
        /// <param name="c2">The second comment to compare.</param>
        /// <param name="options">The options to use in the comparison.</param>
        /// <returns>true if the comments are equal, false otherwise.</returns>
        public static bool DeepEquals(this XComment c1, XComment c2, ComparisonOptions options)
        {
            if ((c1 ?? c2) == null)
                return true;
            if ((c1 == null) || (c2 == null))
                return false; // They are not both null, so if either is, then the other isn't

            return c1.Value == c2.Value;
        }
开发者ID:Andrea,项目名称:nxmpp,代码行数:16,代码来源:XNodeExtension.cs


示例6: CreateDocumentWithContent

        public void CreateDocumentWithContent()
        {
            XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
            XComment comment = new XComment("This is a document");
            XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
            XElement element = new XElement("RootElement");

            XDocument doc = new XDocument(declaration, comment, instruction, element);

            Assert.Equal(new XNode[] { comment, instruction, element }, doc.Nodes());
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:11,代码来源:SDMDocument.cs


示例7: Comment

                //[Variation(Priority = 0, Desc = "XComment - not equals, hashconflict", Params = new object[] { "AAAAP", "AAAAQ", false })]
                //[Variation(Priority = 0, Desc = "XComment - equals", Params = new object[] { "AAAAP", "AAAAP", true })]
                //[Variation(Priority = 3, Desc = "XComment - Whitespaces (negative)", Params = new object[] { "  ", " ", false })]
                //[Variation(Priority = 3, Desc = "XComment - Whitespaces", Params = new object[] { " ", " ", true })]
                //[Variation(Priority = 1, Desc = "XComment - Empty", Params = new object[] { "", "", true })]
                public void Comment()
                {
                    bool expected = (bool)Variation.Params[2];
                    XComment c1 = new XComment(Variation.Params[0] as string);
                    XComment c2 = new XComment(Variation.Params[1] as string);
                    VerifyComparison(expected, c1, c2);

                    XDocument doc = new XDocument(c1);
                    XElement e2 = new XElement("p2p", c2);

                    VerifyComparison(expected, c1, c2);
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:17,代码来源:DeepEquals.cs


示例8: CommentEquals

        public void CommentEquals()
        {
            XComment c1 = new XComment("xxx");
            XComment c2 = new XComment("xxx");
            XComment c3 = new XComment("yyy");

            Assert.False(c1.Equals(null));
            Assert.False(c1.Equals("foo"));
            Assert.True(c1.Equals(c1));
            Assert.False(c1.Equals(c2));
            Assert.False(c1.Equals(c3));
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:12,代码来源:SDMComment.cs


示例9: CommentValue

        public void CommentValue()
        {
            XComment c = new XComment("xxx");
            Assert.Equal("xxx", c.Value);

            // Null value not allowed.
            Assert.Throws<ArgumentNullException>(() => c.Value = null);

            // Try setting a value.
            c.Value = "abcd";
            Assert.Equal("abcd", c.Value);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:SDMComment.cs


示例10: ContainerAdd

                /// <summary>
                /// Tests the Add methods on Container.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "ContainerAdd")]
                public void ContainerAdd()
                {
                    XElement element = new XElement("foo");

                    // Adding null does nothing.
                    element.Add(null);
                    Validate.Count(element.Nodes(), 0);

                    // Add node, attrbute, string, some other value, and an IEnumerable.
                    XComment comment = new XComment("this is a comment");
                    XComment comment2 = new XComment("this is a comment 2");
                    XComment comment3 = new XComment("this is a comment 3");
                    XAttribute attribute = new XAttribute("att", "att-value");
                    string str = "this is a string";
                    int other = 7;

                    element.Add(comment);
                    element.Add(attribute);
                    element.Add(str);
                    element.Add(other);
                    element.Add(new XComment[] { comment2, comment3 });

                    Validate.EnumeratorDeepEquals(
                        element.Nodes(),
                        new XNode[] { comment, new XText(str + other), comment2, comment3 });

                    Validate.EnumeratorAttributes(element.Attributes(), new XAttribute[] { attribute });

                    element.RemoveAll();
                    Validate.Count(element.Nodes(), 0);

                    // Now test params overload.
                    element.Add(comment, attribute, str, other);

                    Validate.EnumeratorDeepEquals(
                        element.Nodes(),
                        new XNode[] { comment, new XText(str + other) });

                    Validate.EnumeratorAttributes(element.Attributes(), new XAttribute[] { attribute });

                    // Not allowed to add a document as a child.
                    XDocument document = new XDocument();
                    try
                    {
                        element.Add(document);
                        Validate.ExpectedThrow(typeof(ArgumentException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentException));
                    }
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:58,代码来源:SDMContainer.cs


示例11: CreateDocumentCopy

                /// <summary>
                /// Validate behavior of the XDocument copy/clone constructor.
                /// </summary>
                /// <returns>true if pass, false if fail</returns>
                //[Variation(Desc = "CreateDocumentCopy")]
                public void CreateDocumentCopy()
                {
                    try
                    {
                        new XDocument((XDocument)null);
                        Validate.ExpectedThrow(typeof(ArgumentNullException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentNullException));
                    }

                    XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
                    XComment comment = new XComment("This is a document");
                    XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
                    XElement element = new XElement("RootElement");

                    XDocument doc = new XDocument(declaration, comment, instruction, element);

                    XDocument doc2 = new XDocument(doc);

                    IEnumerator e = doc2.Nodes().GetEnumerator();

                    // First node: declaration
                    Validate.IsEqual(doc.Declaration.ToString(), doc2.Declaration.ToString());

                    // Next node: comment
                    Validate.IsEqual(e.MoveNext(), true);
                    Validate.Type(e.Current, typeof(XComment));
                    Validate.IsNotReferenceEqual(e.Current, comment);
                    XComment comment2 = (XComment)e.Current;
                    Validate.IsEqual(comment2.Value, comment.Value);

                    // Next node: processing instruction
                    Validate.IsEqual(e.MoveNext(), true);
                    Validate.Type(e.Current, typeof(XProcessingInstruction));
                    Validate.IsNotReferenceEqual(e.Current, instruction);
                    XProcessingInstruction instruction2 = (XProcessingInstruction)e.Current;
                    Validate.String(instruction2.Target, instruction.Target);
                    Validate.String(instruction2.Data, instruction.Data);

                    // Next node: element.
                    Validate.IsEqual(e.MoveNext(), true);
                    Validate.Type(e.Current, typeof(XElement));
                    Validate.IsNotReferenceEqual(e.Current, element);
                    XElement element2 = (XElement)e.Current;
                    Validate.ElementName(element2, element.Name.ToString());
                    Validate.Count(element2.Nodes(), 0);

                    // Should be end.
                    Validate.IsEqual(e.MoveNext(), false);
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:57,代码来源:SDMDocument.cs


示例12: CommentDeepEquals

        public void CommentDeepEquals()
        {
            XComment c1 = new XComment("xxx");
            XComment c2 = new XComment("xxx");
            XComment c3 = new XComment("yyy");

            Assert.False(XNode.DeepEquals(c1, (XComment)null));
            Assert.True(XNode.DeepEquals(c1, c1));
            Assert.True(XNode.DeepEquals(c1, c2));
            Assert.False(XNode.DeepEquals(c1, c3));

            Assert.Equal(XNode.EqualityComparer.GetHashCode(c1), XNode.EqualityComparer.GetHashCode(c2));
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:13,代码来源:SDMComment.cs


示例13: XmlGenerator

 //constructor in which all the member variables are initialised     
 public XmlGenerator()
 {
     try
     {
         xmlDocument = new XDocument();
         xmlDocument.Declaration = new XDeclaration("1.0", "utf-8", "yes");
         xmlDocumentComment = new XComment("Generates XML Output for the Analyzed data");
         xmRootElement = new XElement("AnalysisResult");
     }
     catch
     {
         Console.WriteLine("Error occurred while generating the XML file");
     }
 }
开发者ID:prmk,项目名称:DependencyAnalyzer,代码行数:15,代码来源:XMLGenerator.cs


示例14: NodeTypes

                //[Variation(Desc = "NodeTypes")]
                public void NodeTypes()
                {
                    XDocument document = new XDocument();
                    XElement element = new XElement("x");
                    XText text = new XText("text-value");
                    XComment comment = new XComment("comment");
                    XProcessingInstruction processingInstruction = new XProcessingInstruction("target", "data");

                    Validate.IsEqual(document.NodeType, XmlNodeType.Document);
                    Validate.IsEqual(element.NodeType, XmlNodeType.Element);
                    Validate.IsEqual(text.NodeType, XmlNodeType.Text);
                    Validate.IsEqual(comment.NodeType, XmlNodeType.Comment);
                    Validate.IsEqual(processingInstruction.NodeType, XmlNodeType.ProcessingInstruction);
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:15,代码来源:SDMMisc.cs


示例15: InitDebils

 public static void InitDebils()
 {
     XDocument Debili = new XDocument();
       XDeclaration Xdec = new XDeclaration("1.0", "utf-8", "yes");
       XComment Com = new XComment("Не изменяйте нижнюю строчку");
       XElement Stud =  new XElement("StudList",
       new XElement("Class", new XAttribute("ID", 1),
     new XElement("Name", "Витек Мартынов"),
     new XElement("Name", "Батруха Иисусов"),
     new XElement("Name", "Шланг Волосатый")));
       //Debili.Add(Xdec);
       Debili.Add(Stud);
       Debili.Save("Test.xml");
 }
开发者ID:Mexahoid,项目名称:CSF,代码行数:14,代码来源:Heart.cs


示例16: NodeTypes

        public void NodeTypes()
        {
            XDocument document = new XDocument();
            XElement element = new XElement("x");
            XText text = new XText("text-value");
            XComment comment = new XComment("comment");
            XProcessingInstruction processingInstruction = new XProcessingInstruction("target", "data");

            Assert.Equal(XmlNodeType.Document, document.NodeType);
            Assert.Equal(XmlNodeType.Element, element.NodeType);
            Assert.Equal(XmlNodeType.Text, text.NodeType);
            Assert.Equal(XmlNodeType.Comment, comment.NodeType);
            Assert.Equal(XmlNodeType.ProcessingInstruction, processingInstruction.NodeType);
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:14,代码来源:SDMMisc.cs


示例17: SaveToXmlFile

 public void SaveToXmlFile(string fileName)
 {
     XDocument xDoc = new XDocument {Declaration = new XDeclaration("1.0", "utf-8", "yes")};
     XComment xComment = new XComment("Manga Reading Assistant Database Exporter");
     xDoc.Add(xComment, new XElement("MangaDatabase"));
     if (xDoc.Root != null)
     {
         xDoc.Root.Add(PublisherXElement(DatabaseWrapper.Instance.GetAllPublisherInfoElements()));
         xDoc.Root.Add(GenresXElement(DatabaseWrapper.Instance.GetAllGenreInfoElements()));
         xDoc.Root.Add(AuthorXElement(DatabaseWrapper.Instance.GetAllAuthorInfoElements()));
         xDoc.Root.Add(MangaXElement(DatabaseWrapper.Instance.GetAllMangaInfoElements()));
         xDoc.Root.Add(MangaGenreXElement(DatabaseWrapper.Instance.GetAllMangaGenreElements()));
         xDoc.Root.Add(MangaAuthorsXElement(DatabaseWrapper.Instance.GetAllMangaAuthorElements()));
     }
     xDoc.Save(fileName);
 }
开发者ID:kelsos,项目名称:mra-net-sharp,代码行数:16,代码来源:IoWrapper.cs


示例18: CreateDocumentCopy

        public void CreateDocumentCopy()
        {
            Assert.Throws<ArgumentNullException>(() => new XDocument((XDocument)null));

            XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
            XComment comment = new XComment("This is a document");
            XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
            XElement element = new XElement("RootElement");

            XDocument doc = new XDocument(declaration, comment, instruction, element);

            XDocument doc2 = new XDocument(doc);

            IEnumerator e = doc2.Nodes().GetEnumerator();

            // First node: declaration
            Assert.Equal(doc.Declaration.ToString(), doc2.Declaration.ToString());

            // Next node: comment
            Assert.True(e.MoveNext());
            Assert.IsType<XComment>(e.Current);
            Assert.NotSame(comment, e.Current);

            XComment comment2 = (XComment)e.Current;
            Assert.Equal(comment.Value, comment2.Value);

            // Next node: processing instruction
            Assert.True(e.MoveNext());
            Assert.IsType<XProcessingInstruction>(e.Current);
            Assert.NotSame(instruction, e.Current);

            XProcessingInstruction instruction2 = (XProcessingInstruction)e.Current;
            Assert.Equal(instruction.Target, instruction2.Target);
            Assert.Equal(instruction.Data, instruction2.Data);

            // Next node: element.
            Assert.True(e.MoveNext());
            Assert.IsType<XElement>(e.Current);
            Assert.NotSame(element, e.Current);

            XElement element2 = (XElement)e.Current;
            Assert.Equal(element.Name.ToString(), element2.Name.ToString());
            Assert.Empty(element2.Nodes());

            // Should be end.
            Assert.False(e.MoveNext());
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:47,代码来源:SDMDocument.cs


示例19: displayFunctionAnalysis

        //--------------------<displays the Function Analysis in XML format>-----------------------------
        public void displayFunctionAnalysis()
        {
            List<Elem> outputList = OutputRepository.output_;
            if (outputList.Count == 0)
            {
                Console.Write("No Data in FunctionAnalysis");
                return;
            }
            Console.Write("\n  Created XML for Function size and Complexity");
            Console.Write("\n =====================================\n");
            XDocument xml = new XDocument();
            xml.Declaration = new XDeclaration("1.0", "utf-8", "yes");
            XComment comment = new XComment("Demonstration XML");
            xml.Add(comment);
            XElement root = new XElement("CODEANALYSIS");
            xml.Add(root);
            foreach (Elem e in outputList)
            {                                                                 //Addition of Child
                int size = e.end - e.begin;
                XElement childType = new XElement("Type");
                root.Add(childType);
                XElement type = new XElement("Type", e.type);
                childType.Add(type);

                XElement childName = new XElement("NAME");
                root.Add(childName);
                XElement name = new XElement("Name", e.name);
                childName.Add(name);

                XElement childComplexity = new XElement("COMPLEXITY");
                root.Add(childComplexity);
                XElement functionComplexity = new XElement("Complexity", Convert.ToString(e.functionComplexity));
                childComplexity.Add(functionComplexity);

                XElement childSize = new XElement("SIZE");
                root.Add(childSize);
                XElement sizeNew = new XElement("Size", Convert.ToString(size));
                childSize.Add(sizeNew);
                xml.Save(Directory.GetCurrentDirectory() + "\\FunctionAnalysis.xml");
            }
            Console.Write(" The Size and Complexity XML file is displayed at:\n");
            Console.Write(" ");
            Console.Write(Directory.GetCurrentDirectory());
            Console.Write("\\FunctionAnalysis.xml");
            Console.Write("\n\n");
        }
开发者ID:WaverV,项目名称:Projects,代码行数:47,代码来源:XMLOutput.cs


示例20: create_xml_from_db

        /*
             *  It is a quirk of the XDocument class that the XML declaration,
             *  a valid element, cannot be added to the XDocument's element
             *  collection.  Instead, it must be assigned to the document's
             *  Declaration property.
             */

            /* 
            * we are creating XElements for each DBElement<int, string> in 
            * DBEngine<int, DBElement<int, string>> using XElement object
            * We are saving XMl file to ~/TestExec/bin/debug/Test_DB.xml
            */
        public static void create_xml_from_db(this DBEngine<int, DBElement<int, string>> db, Boolean persist)
        {
            XDocument xml = new XDocument();
            xml.Declaration = new XDeclaration("1.0", "utf-8", "yes");
            XComment comment = new XComment("Test DB data to XML");
            xml.Add(comment);
            XElement root = new XElement("noSQL");
            xml.Add(root);
            XElement keytype = new XElement("keytype", "integer");
            root.Add(keytype);
            XElement payloadtype = new XElement("payloadtype", "string");
            root.Add(payloadtype);
            foreach (var db_key in db.Keys())
            {
                DBElement<int, string> ele = new DBElement<int, string>();
                db.getValue(db_key, out ele);
                XElement key = new XElement("key", db_key);
                root.Add(key);
                XElement element = new XElement("element");
                XElement name = new XElement("name", ele.name);
                XElement descr = new XElement("descr", ele.descr);
                XElement timestamp = new XElement("timestamp", ele.timeStamp);
                XElement children = new XElement("children");
                XElement payload = new XElement("payload", ele.payload);
                foreach (int x in ele.children)
                {
                    XElement children_key = new XElement("key", x);
                    children.Add(children_key);
                }
                element.Add(name);
                element.Add(descr);
                element.Add(timestamp);
                element.Add(children);
                element.Add(payload);
                root.Add(element);
            }
            WriteLine();
            //<--------Writing to XML--------->
            "Creating XML file using XDocument and writing into Test_DB.xml".title();
            xml.Save("Test_DB.xml");
            display_xml(xml, persist);
            WriteLine();
        }
开发者ID:yogeshchaudhari16991,项目名称:NoSQLDatabase,代码行数:55,代码来源:PersistEngine.cs



注:本文中的System.Xml.Linq.XComment类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Linq.XContainer类代码示例发布时间:2022-05-26
下一篇:
C# Linq.XAttribute类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap