本文整理汇总了C#中IEnumerable.Elements方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.Elements方法的具体用法?C# IEnumerable.Elements怎么用?C# IEnumerable.Elements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.Elements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GameParameters
private GameParameters()
{
Path = System.Environment.CurrentDirectory;
_xmlDoc = XDocument.Load(ParameterPath);
_root = _xmlDoc.Descendants("GameParameters");
Type = GameType.Classic;
GameTime = Convert.ToInt32(_root.Elements("CommonParameter").Elements("GameTime").FirstOrDefault().Attribute("count").Value);
Network = Network.Local;
Theme = "Basic";
_menutextureList = new Dictionary<string, BitmapImage>();
ExplosionDelay = Convert.ToInt32(_root.Elements("CommonParameter").Elements("ExplosionDelay").FirstOrDefault().Attribute("count").Value);
LoadAllSystemResources();
}
示例2: GetVarfield
public static string GetVarfield(IEnumerable<XElement> nodes, string id, string subfieldLabel)
{
var varfield =
nodes.Elements("varfield").Where(x => ((string)x.Attribute("id")).Equals(id)).Elements("subfield");
return
varfield.Where(x => ((string)x.Attribute("label")).Equals(subfieldLabel)).Select(x => x.Value).FirstOrDefault();
}
示例3: GetMatchingSongIdElements
private static IEnumerable<XElement> GetMatchingSongIdElements(IEnumerable<XElement> songs, string songId)
{
Debug.WriteLine(songs.Count());
var songIdElements = songs.Elements("id");
Debug.WriteLine("ids" + songIdElements.Count());
var songIdElement = songIdElements.Where(el => el.Value.Equals(songId));
return songIdElement;
}
示例4: LoadTasksForItem
private IEnumerable<Task> LoadTasksForItem(IEnumerable<XElement> childrenElement, int parentId)
{
// Get the "child" elements of this element, which would be the tasks
var tasks = childrenElement.Elements("child");
if (tasks != null && tasks.Count() > 0)
{
foreach (var task in tasks)
{
yield return CreateTask(task, parentId);
}
}
}
示例5: GetPdfInfos
public static List<PdfInfo> GetPdfInfos(IEnumerable<XElement> pdfInfosElement)
{
IEnumerable<XElement> elements = pdfInfosElement.Elements("PdfInfo");
var pdfInfos = new List<PdfInfo>();
foreach (XElement element in elements)
{
// TODO validate by using a schema
string filePrefix = element.Element("FilePrefix").Value;
string folder = element.Element("Folder").Value;
string textRegExPattern = element.Element("TextRegExPattern").Value;
string dateRegExPattern = element.Element("DateRegExPattern").Value;
var pdfInfo = new PdfInfo(filePrefix, folder, textRegExPattern, dateRegExPattern);
pdfInfos.Add(pdfInfo);
}
return pdfInfos;
}
示例6: LoadSettings
// Invoked from World.Settings
internal static void LoadSettings(IEnumerable<XElement> xmlToolSettings)
{
foreach (var xElement in xmlToolSettings.Elements("Tool"))
{
string toolName = (string)xElement.Attribute("Name");
switch (toolName)
{
case "Paint":
_paintMode = (PaintMode)ToEnum(typeof(PaintMode), (string)xElement.Attribute("Mode") ?? PaintMode.TileAndWall.ToString());
break;
case "Brush":
_brushWidth = (int?)xElement.Attribute("Width") ?? 20;
_brushHeight = (int?)xElement.Attribute("Height") ?? 20;
_brushOutline = (int?)xElement.Attribute("Outline") ?? 1;
_brushShape = (BrushShape)ToEnum(typeof(BrushShape), (string)xElement.Attribute("Shape") ?? BrushShape.Square.ToString());
break;
case "Tile":
_paintTile = (int?)xElement.Attribute("Tile") ?? 0;
_paintTileMask = (int?)xElement.Attribute("Mask") ?? 0;
_paintTileActive = (bool)xElement.Attribute("Active");
_paintTileMaskMode = (MaskMode)ToEnum(typeof(MaskMode), (string)xElement.Attribute("Mode") ?? MaskMode.Off.ToString());
break;
case "Wall":
_paintWall = (int?)xElement.Attribute("Wall") ?? 0;
_paintWallMask = (int?)xElement.Attribute("Mask") ?? 0;
_paintWallActive = (bool)xElement.Attribute("Active");
_paintWallMaskMode = (MaskMode)ToEnum(typeof(MaskMode), (string)xElement.Attribute("Mode") ?? MaskMode.Off.ToString());
break;
case "Wire":
_redWire = (bool)xElement.Attribute("Red");
_blueWire = (bool)xElement.Attribute("Blue");
_greenWire = (bool)xElement.Attribute("Green");
break;
}
}
}
示例7: GetActions
public static bool GetActions(IEnumerable<XElement> actionsXml, out IList<IHttpAction> actions, out IList<IRequestAction> requestActions, out IList<IResponseAction> responseActions)
{
actions = new List<IHttpAction>();
requestActions = new List<IRequestAction>();
responseActions = new List<IResponseAction>();
var actionsTemp = actions;
Func<IList<IHttpAction>, IHttpAction, bool> addFunc = (a, ra) =>
{
a.Add(ra);
return true;
}; // hmm, this is just to keep the query below as a single statement, perhaps there is a better way?
foreach (var ruleAction in from actionXml in actionsXml.Elements()
let name = actionXml.Name.ToString()
where RuleActionTypes.ContainsKey(name)
let actionType = RuleActionTypes[name]
where actionType != null
let constructor = actionType.GetConstructor(new Type[] {})
where constructor != null
let ruleAction = (IHttpAction) constructor.Invoke(new object[] {})
where ruleAction != null && addFunc(actionsTemp, ruleAction)
where ruleAction.Deserialize(actionXml)
select ruleAction)
{
if (ruleAction is IRequestAction)
{
requestActions.Add((IRequestAction)ruleAction);
}
if (ruleAction is IResponseAction)
{
responseActions.Add((IResponseAction)ruleAction);
}
}
return true;
}
示例8: GetXElementByLocalName
private IEnumerable<XElement> GetXElementByLocalName(IEnumerable<XElement> xElements, String eName)
{
if (xElements != null)
{
IEnumerable<XElement> returnValues = xElements.Where(x => x.Name.LocalName == eName);
if (returnValues.Count() > 0)
return returnValues;
else if (xElements.Elements().Count() > 0)
return GetXElementByLocalName(xElements.Elements(), eName);
}
return null;
}
示例9: GetFileNameElements
private static IEnumerable<XElement> GetFileNameElements(string filename, IEnumerable<XElement> files)
{
var fileNameElement = files.Elements("name").Where(el => el.Value.Equals(filename));
return fileNameElement;
}
示例10: GetVarfieldAsList
protected static IEnumerable<string> GetVarfieldAsList(IEnumerable<XElement> nodes, string id,
string subfieldLabel)
{
var varfield =
nodes.Elements("varfield").Where(x => ((string)x.Attribute("id")).Equals(id)).Elements("subfield");
return varfield.Where(x => ((string)x.Attribute("label")).Equals(subfieldLabel)).Select(x => x.Value).ToList();
}
示例11: GetFixfield
private static string GetFixfield(IEnumerable<XElement> nodes, string id, int fromPos, int toPos)
{
var fixfield = nodes.Elements("fixfield").Where(x => ((string)x.Attribute("id")).Equals(id)).Select(x => x.Value).FirstOrDefault();
if (!string.IsNullOrEmpty(fixfield) && toPos < fixfield.Length)
{
if (fromPos == toPos)
{
return fixfield.ElementAt(fromPos).ToString();
}
else
{
return fixfield.Substring(fromPos, (toPos - fromPos) + 1);
}
}
else
{
return "";
}
}
示例12: FixRange
// If the set of paragraphs from sourceDocument don't have a complete start/end for bookmarks,
// comments, etc., then this adds them to the paragraph. Note that this adds them to
// sourceDocument, and is impure.
private static void FixRange(XDocument sourceDocument, IEnumerable<XElement> newContent,
XName startElement, XName endElement, XName idAttribute, XName refElement)
{
foreach (XElement start in newContent.DescendantsAndSelf(startElement))
{
string rangeId = start.Attribute(idAttribute).Value;
if (newContent
.DescendantsAndSelf(endElement)
.Where(e => e.Attribute(idAttribute).Value == rangeId)
.Count() == 0)
{
XElement end = sourceDocument
.Descendants(endElement)
.Where(o => o.Attribute(idAttribute).Value == rangeId)
.FirstOrDefault();
if (end != null)
{
AddAtEnd(newContent, new XElement(end));
if (refElement != null)
{
XElement newRef = new XElement(refElement, new XAttribute(idAttribute, rangeId));
AddAtEnd(newContent, new XElement(newRef));
}
}
}
}
foreach (XElement end in newContent.Elements(endElement))
{
string rangeId = end.Attribute(idAttribute).Value;
if (newContent
.DescendantsAndSelf(startElement)
.Where(s => s.Attribute(idAttribute).Value == rangeId)
.Count() == 0)
{
XElement start = sourceDocument
.Descendants(startElement)
.Where(o => o.Attribute(idAttribute).Value == rangeId)
.FirstOrDefault();
if (start != null)
AddAtBeginning(newContent, new XElement(start));
}
}
}
示例13: ParseSchema
public IEnumerable<XElement> ParseSchema(string tag, IEnumerable<XElement> data, XNamespace nsSchema)
{
var query = from e in data.Elements(nsSchema + tag)
select e;
return query;
}
示例14: AddPersonAttributes
/// <summary>
/// Adds the person attributes and values found in the XML to the person's attribute-value collection.
/// </summary>
/// <param name="groupMember"></param>
/// <param name="attributes"></param>
private void AddPersonAttributes( GroupMember groupMember, IEnumerable<XElement> attributes, RockContext rockContext )
{
// In order to add attributes to the person, you have to first load them all
groupMember.Person.LoadAttributes( rockContext );
foreach ( var personAttribute in attributes.Elements( "attribute" ) )
{
// Add them to the list of people who need to have their attribute values saved.
// This will be done after all the family groups have been saved.
_personWithAttributes[groupMember.Person.Guid] = true;
foreach ( var pa in personAttribute.Attributes() )
{
groupMember.Person.SetAttributeValue( pa.Name.LocalName, pa.Value );
}
}
}
示例15: FixRange
private static void FixRange(XDocument oldDoc, IEnumerable<XElement> paragraphs, XName startElement, XName endElement, XName idAttribute, XName refElement)
{
foreach (XElement start in paragraphs.Elements(startElement))
{
string rangeId = start.Attribute(idAttribute).Value;
if (paragraphs.Elements(endElement).Where(e => e.Attribute(idAttribute).Value == rangeId).Count() == 0)
{
XElement end = oldDoc.Descendants().Elements(endElement).Where(o => o.Attribute(idAttribute).Value == rangeId).First();
if (end != null)
{
paragraphs.Last().Add(new XElement(end));
if (refElement != null)
{
XElement newRef = new XElement(refElement, new XAttribute(idAttribute, rangeId));
paragraphs.Last().Add(newRef);
}
}
}
}
foreach (XElement end in paragraphs.Elements(endElement))
{
string rangeId = end.Attribute(idAttribute).Value;
if (paragraphs.Elements(startElement).Where(s => s.Attribute(idAttribute).Value == rangeId).Count() == 0)
{
XElement start = oldDoc.Descendants().Elements(startElement).Where(o => o.Attribute(idAttribute).Value == rangeId).First();
if (start != null)
paragraphs.First().AddFirst(new XElement(start));
}
}
}