本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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));
}
}
示例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)
);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
示例12: BrowserSource
public BrowserSource(XElement configElement)
{
this.configElement = configElement;
this.browserConfig = new BrowserConfig();
this.textureMap = new Dictionary<IntPtr, Texture>();
UpdateSettings();
}
示例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;
}
示例14: DccObsImageSource
public DccObsImageSource(XElement config)
{
ExecuteCmd("LiveViewWnd_Show");
Thread.Sleep(1000);
ExecuteCmd("All_Minimize");
this.config = config;
UpdateSettings();
}
示例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);
}