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


C# XElement类代码示例

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


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

示例1: DefaultNamespaceDifferentNameElements

 public void DefaultNamespaceDifferentNameElements()
 {
     var a = new XElement("NameOne");
     var b = new XElement("NameTwo");
     Assert.Same(a.Name.Namespace, b.Name.Namespace);
     Assert.NotSame(a.Name, b.Name);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:XHashtable.cs

示例2: SameNamespaceDifferentNamesElements

 public void SameNamespaceDifferentNamesElements()
 {
     var a = new XElement("{NameSpace}NameOne");
     var b = new XElement("{NameSpace}NameTwo");
     Assert.Same(a.Name.Namespace, b.Name.Namespace);
     Assert.NotSame(a.Name, b.Name);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:XHashtable.cs

示例3: Main

    static void Main()
    {
        // Create the data source by using a collection initializer.
            // The Student class was defined previously in this topic.
            List<Student> students = new List<Student>()
            {
                new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores = new List<int>{97, 92, 81, 60}},
                new Student {First="Claire", Last="O’Donnell", ID=112, Scores = new List<int>{75, 84, 91, 39}},
                new Student {First="Sven", Last="Mortensen", ID=113, Scores = new List<int>{88, 94, 65, 91}},
            };

            // Create the query.
            var studentsToXML = new XElement("Root",
                from student in students
                let x = String.Format("{0},{1},{2},{3}", student.Scores[0],
                        student.Scores[1], student.Scores[2], student.Scores[3])
                select new XElement("student",
                           new XElement("First", student.First),
                           new XElement("Last", student.Last),
                           new XElement("Scores", x)
                        ) // end "student"
                    ); // end "Root"

            // Execute the query.
            Console.WriteLine(studentsToXML);

            // Keep the console open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
    }
开发者ID:terryjintry,项目名称:OLSource1,代码行数:30,代码来源:data-transformations-with-linq--csharp-_3.cs

示例4: Reload

        public void Reload(XElement element)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            BrowserSourceSettings = AbstractSettings.DeepClone(BrowserSettings.Instance.SourceSettings);
            BrowserInstanceSettings = AbstractSettings.DeepClone(BrowserSettings.Instance.InstanceSettings);

            String instanceSettingsString = element.GetString("instanceSettings");
            String sourceSettingsString = element.GetString("sourceSettings");

            if (sourceSettingsString != null && sourceSettingsString.Count() > 0)
            {
                try
                {
                    BrowserSourceSettings = serializer.Deserialize<BrowserSourceSettings>(sourceSettingsString);
                }
                catch (ArgumentException e)
                {
                    API.Instance.Log("Failed to deserialized source settings and forced to recreate; {0}", e.Message);
                }
            }

            if (instanceSettingsString != null && instanceSettingsString.Count() > 0)
            {
                BrowserInstanceSettings.MergeWith(serializer.Deserialize<BrowserInstanceSettings>(instanceSettingsString));
            }
        }
开发者ID:jameshearn,项目名称:CLRBrowserSourcePlugin,代码行数:27,代码来源:BrowserConfig.cs

示例5: InsertAttribute

		/// <summary>
		/// Inserts an attribute to an XElement in the source code editor.
		/// </summary>
		/// <param name='el'>
		/// the tag's XElement instance
		/// </param>
		/// <param name='key'>
		/// Key.
		/// </param>
		/// <param name='value'>
		/// Value.
		/// </param>
		public void InsertAttribute (XElement el, string key, string value)
		{
			int line = el.Region.EndLine;
			int column = 1;
			// a preceding space or nothing
			string preambula = String.Empty;
			// a space or nothing after the last quote
			string ending = String.Empty;

			if (el.IsSelfClosing) {
				column = el.Region.EndColumn - 2; // "/>"
				// a space before the /> of the tag
				ending = " ";
			} else {
				column = el.Region.EndColumn -1; // ">"
				// no need for a space in the end of an openning tag
			}

			// check if a space is needed infront of the attribute
			// or the method should write at the first column of a new line
			if (column > 1) {
				string whatsBeforeUs = document.GetTextFromEditor (line, column - 1, line, column);
				if (!String.IsNullOrWhiteSpace (whatsBeforeUs))
					preambula = " ";
			}

			// finally, insert the result
			document.InsertText (
				new TextLocation (line, column),
				String.Format ("{0}{1}=\"{2}\"{3}", preambula, key, value, ending)
			);
		}
开发者ID:segaman,项目名称:monodevelop,代码行数:44,代码来源:DesignerSerializer.cs

示例6: ShowConfiguration

        public override bool ShowConfiguration(XElement config)
        {
            var dialog = new LiveSplitConfigurationDialog(config);
            if (dialog.ShowDialog().GetValueOrDefault(false))
            {
                if (config.Parent.GetInt("cx") == 0 || config.Parent.GetInt("cy") == 0)
                {
                    try
                    {
                        using (var layoutStream = System.IO.File.OpenRead(config.GetString("layoutpath")))
                        {
                            var xmlDoc = new System.Xml.XmlDocument();
                            xmlDoc.Load(layoutStream);

                            var parent = xmlDoc["Layout"];
                            var width = parent["VerticalWidth"];
                            config.Parent.SetInt("cx", int.Parse(width.InnerText));
                            var height = parent["VerticalHeight"];
                            config.Parent.SetInt("cy", int.Parse(height.InnerText)); //TODO Will break with horizontal
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                    }
                }

                return true;
            }
            return false;
        }
开发者ID:PrototypeAlpha,项目名称:LiveSplit,代码行数:31,代码来源:LiveSplitImageSourceFactory.cs

示例7: Main

        private static void Main()
        {
            helper.ConsoleMio.Setup();
            helper.ConsoleMio.PrintHeading("Extract Contact Information");

            string selctedFile = SelectFileToOpen();

            string saveLocation = SelectSaveLocation();

            var contactInfo = new XElement("person");
            
            using (var inputStream = new StreamReader(selctedFile))
            {
                string currentLine;
                while ((currentLine = inputStream.ReadLine()) != null)
                {
                    string[] args = currentLine.Split(' ');
                    string tag = args[0];
                    string content = string.Join(" ", args.Skip(1).ToArray());

                    contactInfo.Add(new XElement(tag, content));
                }
            }

            contactInfo.Save(saveLocation);

            helper.ConsoleMio.PrintColorText("Completed\n ", ConsoleColor.Green);
            
            helper.ConsoleMio.Restart(Main);
        }
开发者ID:kidroca,项目名称:Databases,代码行数:30,代码来源:ParseTextXml.cs

示例8: AddMember

		void AddMember (XElement element)
		{
			string id;
			if (element.IsRunatServer () && !string.IsNullOrEmpty (id = element.GetId ())) {
				
				if (Members.ContainsKey (id)) {
					Errors.Add (new Error (
						ErrorType.Error,
						GettextCatalog.GetString ("Tag ID must be unique within the document: '{0}'.", id),
						element.Region
					)
					);
				} else {
					string controlType = element.Attributes.GetValue (new XName ("type"), true);
					IType type = docRefMan.GetType (element.Name.Prefix, element.Name.Name, controlType);
	
					if (type == null) {
						Errors.Add (
							new Error (
								ErrorType.Error,
								GettextCatalog.GetString ("The tag type '{0}{1}{2}' has not been registered.", 
						                          element.Name.Prefix, 
						                          element.Name.HasPrefix ? string.Empty : ":", 
						                          element.Name.Name),
								element.Region
							)
						);
					} else
						Members [id] = new CodeBehindMember (id, type, element.Region.Begin);
				}

			}
			foreach (XElement child in element.Nodes.OfType<XElement> ())
				AddMember (child);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:35,代码来源:MemberListBuilder.cs

示例9: FromXElement

        /// <summary>
        /// Converts a given <see cref="T:XElement"/> into a <see cref="T:ChangeSetHistory"/>.
        /// </summary>
        /// <param name="element">The <see cref="T:XElement"/> to convert.</param>
        /// <returns>The newly created <see cref="T:ChangeSetHistory"/>.</returns>
        public ChangeSetHistory FromXElement(XElement element)
        {
            ChangeSetHistory history = new ChangeSetHistory();
            foreach (XElement changeSetElement in element.Nodes()) {
                ChangeSet changeSet = new ChangeSet();

                // Get the change set details
                foreach (XElement changeSetElementChild in changeSetElement.Nodes()) {
                    if (changeSetElementChild.Name.LocalName == "Applied") {
                        changeSet.Applied = DateTime.Parse(changeSetElementChild.Value);
                    } else if (changeSetElementChild.Name.LocalName == "Username") {
                        changeSet.Username = changeSetElementChild.Value;
                    } else if (changeSetElementChild.Name.LocalName == "Change") {
                        Change change = new Change();
                        foreach (XElement changeElement in changeSetElementChild.Nodes()) {
                            if (changeElement.Name.LocalName == "PropertyName") {
                                change.PropertyName = changeElement.Value;
                            } else if (changeElement.Name.LocalName == "OldValue") {
                                change.OldValue = changeElement.Value;
                            } else if (changeElement.Name.LocalName == "NewValue") {
                                change.NewValue = changeElement.Value;
                            }
                        }
                        changeSet.Changes.Add(change);
                    }
                }
                history.Append(changeSet);
            }
            return history;
        }
开发者ID:PaulStovell,项目名称:trial-balance,代码行数:35,代码来源:ChangeSetHistoryXElementAdapter.cs

示例10: FromXElement

 /// <summary>
 /// Converts a given <see cref="T:XElement"/> into an <see cref="T:Account"/>.
 /// </summary>
 /// <param name="element">The <see cref="T:XElement"/> to convert.</param>
 /// <returns>The newly created <see cref="T:Account"/>.</returns>
 public Account FromXElement(XElement element)
 {
     Account account = AccountFactory.Create(element.Name.LocalName);
     foreach (XElement childNode in element.Nodes()) {
         switch (childNode.Name.LocalName) {
             case "AccountID":
                 account.AccountID = new Guid(childNode.Value);
                 break;
             case "CreatedByUsername":
                 account.CreatedByUsername = childNode.Value;
                 break;
             case "CreatedDate":
                 account.CreatedDate = DateTime.Parse(childNode.Value);
                 break;
             case "Description":
                 account.Description = childNode.Value;
                 break;
             case "Name":
                 account.Name = childNode.Value;
                 break;
             case "UpdatedByUsername":
                 account.UpdatedByUsername = childNode.Value;
                 break;
             case "UpdatedDate":
                 account.UpdatedDate = DateTime.Parse(childNode.Value);
                 break;
             case "ChangeSetHistory":
                 ChangeSetHistoryXElementAdapter adapter = new ChangeSetHistoryXElementAdapter();
                 account.ChangeSetHistory = adapter.FromXElement(childNode);
                 break;
         }
     }
     return account;
 }
开发者ID:PaulStovell,项目名称:trial-balance,代码行数:39,代码来源:AccountXElementAdapter.cs

示例11: SetCustomProperties

 public static void SetCustomProperties(object obj, IEnumerable<PropertyInfo> properties, XElement data)
 {
     foreach (var xmlProperty in data.Descendants("CustomProperty"))
     {
         string propertyName = xmlProperty.Attribute("Name").Value;
         PropertyInfo propertyInfo = properties.Where(info => info.Name == propertyName).First();
     }
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-FIRST-stylecop,代码行数:8,代码来源:2389.cs

示例12: BrowserSource

        public BrowserSource(XElement configElement)
        {
            this.configElement = configElement;
            this.browserConfig = new BrowserConfig();
            this.textureMap = new Dictionary<IntPtr, Texture>();

            UpdateSettings();
        }
开发者ID:jameshearn,项目名称:CLRBrowserSourcePlugin,代码行数:8,代码来源:BrowserSource.cs

示例13: XmlMultipleClosingTagCompletionData

		public XmlMultipleClosingTagCompletionData (XElement finalEl, XElement[] intermediateElements)
		{
			name = finalEl.Name.FullName;
			description = GettextCatalog.GetString ("Closing tag for '{0}', also closing all intermediate tags", name);
			name = string.Format ("/{0}>...", name);
			this.intEls = intermediateElements;
			this.finalEl = finalEl;
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:8,代码来源:XmlMultipleClosingTagCompletionData.cs

示例14: DccObsImageSource

 public DccObsImageSource(XElement config)
 {
     ExecuteCmd("LiveViewWnd_Show");
     Thread.Sleep(1000);
     ExecuteCmd("All_Minimize");
     this.config = config;
     UpdateSettings();
 }
开发者ID:CadeLaRen,项目名称:digiCamControl,代码行数:8,代码来源:DccObsImageSource.cs

示例15: XmlnsNamespaceSameNameElements

 public void XmlnsNamespaceSameNameElements()
 {
     var a = new XElement(XNamespace.Xmlns + "Name");
     var b = new XElement(XNamespace.Xmlns + "Name");
     Assert.Same(XNamespace.Xmlns, a.Name.Namespace);
     Assert.Same(a.Name.Namespace, b.Name.Namespace);
     Assert.Same(a.Name, b.Name);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:XHashtable.cs


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