当前位置: 首页>>代码示例>>C#>>正文


C# Linq.XComment类代码示例

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


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


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