當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。