當前位置: 首頁>>代碼示例>>C#>>正文


C# XElement.Attributes方法代碼示例

本文整理匯總了C#中System.Xml.Linq.XElement.Attributes方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.Attributes方法的具體用法?C# XElement.Attributes怎麽用?C# XElement.Attributes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.Attributes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ProcessElement

        public void ProcessElement(XElement element)
        {
            if (!IsEnabled) return;
            if (!element.HasAttributes) return;

            // Setter? Format "Value" attribute if "Property" atribute matches ThicknessAttributeNames
            if (element.Name == SetterName)
            {
                var propertyAttribute = element.Attributes("Property").FirstOrDefault();
                if (propertyAttribute != null && ThicknessAttributeNames.Any(match => match.IsMatch(propertyAttribute.Value)))
                {
                    var valueAttribute = element.Attributes("Value").FirstOrDefault();
                    if (valueAttribute != null)
                    {
                        FormatAttribute(valueAttribute);
                    }
                }
            }
            // Not setter. Format value of all attributes where attribute name matches ThicknessAttributeNames
            else
            {
                foreach (var attribute in element.Attributes())
                {
                    var isMatchingAttribute = ThicknessAttributeNames.Any(match => match.IsMatch(attribute.Name));
                    if (isMatchingAttribute)
                    {
                        FormatAttribute(attribute);
                    }
                }
            }
        }
開發者ID:NicoVermeir,項目名稱:XamlStyler,代碼行數:31,代碼來源:FormatThicknessService.cs

示例2: BasicValueTypeAttributeCheckIsValid

        private static bool BasicValueTypeAttributeCheckIsValid(XElement element, bool isCustomProperty, out string value)
        {
            Guard.AgainstNull(element, "element");

            if (isCustomProperty)
            {
                if (element.Attributes().Count() != 2)
                {
                    value = "Wrong number of attributes";
                    return false;
                }
                if (element.Attribute(SharedConstants.Name) == null)
                {
                    value = "Custom property has no 'name' attribute";
                    return false;
                }
            }
            else
            {
                if (element.Attributes().Count() != 1)
                {
                    value = "Wrong number of attributes";
                    return false;
                }
            }
            value = element.Attribute(SharedConstants.Val).Value;
            return true;
        }
開發者ID:StephenMcConnel,項目名稱:flexbridge,代碼行數:28,代碼來源:CmObjectValidator.cs

示例3: GetRegexes

		MatchFactory GetRegexes(XElement element) {
			switch (element.Name.LocalName) {
				case "MatchHonorees":
					if (Presentation.MelaveMalka == null)
						return FixedRegexes();
					return FixedRegexes(Presentation.MelaveMalka.Honorees.SelectMany(AdVerifier.GetNameRegexes));
				case "MatchDonors":
					return ad => ad.Row.Pledges.SelectMany(p => AdVerifier.GetNameRegexes(p.Person));
				case "Match":
					return FixedRegexes(new Regex(element.Attribute("Regex").Value));
				case "MatchPerson":
					foreach (var field in element.Attributes())
						if (!Person.Schema.Columns.Contains(field.Name.LocalName))
							throw new ConfigurationException($"Unexpected attribute {field} in <MatchPerson>");
					var fields = element.Attributes().ToDictionary(
						a => a.Name.LocalName,
						a => a.Value
					);
					var people = Program.Table<Person>().Rows.Where(p => fields.All(f => f.Value.Equals(p[f.Key])));
					if (people.Has(2))
						throw new ConfigurationException($"Format rule {element} matches multiple people: {people.Join(", ", p => p.VeryFullName)}");
					var person = people.FirstOrDefault();
					if (person == null)
						throw new ConfigurationException($"Format rule {element} doesn't match anyone in the master directory.");
					return FixedRegexes(AdVerifier.GetNameRegexes(person));
				case "Format":  // Ignore this element.
					return FixedRegexes();
				default:
					throw new ConfigurationException($"Unexpected <{element.Name}> element in <FormatRule>.");
			}
		}
開發者ID:ShomreiTorah,項目名稱:Journal,代碼行數:31,代碼來源:AdFormatter.cs

示例4: GetLocatorPredicate

        public static string GetLocatorPredicate(XElement element)
        {
            var locatorAttribute = element.Attributes(Namespaces.Xdt + "Locator").FirstOrDefault();

            if (locatorAttribute == null)
            {
                return String.Empty;
            }
            else
            {
                var locator = Locator.Parse(locatorAttribute.Value);

                if (locator.Type == "Condition")
                {
                    // use the user-defined value as an xpath predicate
                    return "[" + locator.Arguments + "]";
                }
                else if (locator.Type == "Match")
                {
                    // convenience case of the Condition locator, build the xpath
                    // predicate for the user by matching on all specified attributes

                    var attributeNames = locator.Arguments.Split(',').Select(s => s.Trim());
                    var attributes = element.Attributes().Where(a => attributeNames.Contains(a.Name.LocalName));

                    return "[" + attributes.ToConcatenatedString(a =>
                        "@" + a.Name.LocalName + "='" + a.Value + "'", " and ") + "]";
                }
                else
                {
                    throw new NotImplementedException(String.Format("The Locator '{0}' is not supported", locator.Type));
                }
            }
        }
開發者ID:ngeor,項目名稱:xdt,代碼行數:34,代碼來源:Locator.cs

示例5: ElementToLevelText

        private static string ElementToLevelText(XElement el)
        {
            var blueText = el.Attributes().Any( a => a.Name == "Text") ? el.Attribute("Text").Value : string.Empty;
            var blueAmount = el.Attributes().Any(a => a.Name == "AMOUNT") ? el.Attribute("AMOUNT").Value : string.Empty;
            var blueType = el.Attributes().Any(a => a.Name == "TYPE") ? el.Attribute("TYPE").Value : string.Empty;

            return blueText +" : "+ blueAmount + " " + blueType;
        }
開發者ID:FrankT1983,項目名稱:ZombieCards,代碼行數:8,代碼來源:ZombisideDeckFactory.cs

示例6: DslBuilder

 public DslBuilder(XElement builderClassNode, XmlDocCommentReader commentReader, Type builderType)
 {
     input = builderClassNode.Value;
     syntaxStateClassname = builderClassNode.Attributes().Single(f => f.Name == "name").Value;
     outputNamespace = builderClassNode.Attributes().Single(f => f.Name == "namespace").Value;
     type = builderType;
     this.commentReader = commentReader;
 }
開發者ID:Dervall,項目名稱:Snout,代碼行數:8,代碼來源:DslBuilder.cs

示例7: SetMathVariant

		void SetMathVariant(XElement mathVariant)
		{
			string name = mathVariant.Attribute("name").Value;
			string weight = mathVariant.Attributes("weight").FirstOrDefault() != null ? mathVariant.Attribute("weight").Value : "normal";
			string style = mathVariant.Attributes("style").FirstOrDefault() != null ? mathVariant.Attribute("style").Value : "normal";
			MathVariant mv = new MathVariant(name, weight, style);
			mathVariant.Attribute("family").Value.Split(',').Select(x => x.Trim()).ToList().ForEach(x=> mv.AddFamily(x));
			Variants.Add(name, mv);
		}
開發者ID:acivux,項目名稱:SvgMath,代碼行數:9,代碼來源:MathConfig.cs

示例8: UpdateElement

		/// <summary>
		/// Updates an element from the datasource.
		/// </summary>
		/// <param name="table"></param>
		/// <param name="element"></param>
		public void UpdateElement(IList<XElement> table, XElement element)
		{
			XElement orderToUpdate = (from order in table
									  where order.Attribute(element.Attributes().FirstOrDefault().Name).Value == element.Attributes().FirstOrDefault().Value
									  select order).FirstOrDefault();
			foreach (XElement el in orderToUpdate.Descendants())
			{
				el.Value = element.Element(el.Name).Value;
			}
		}
開發者ID:angelpetrov90,項目名稱:aspnet-sdk,代碼行數:15,代碼來源:XMLContext.cs

示例9: 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

示例10: CreateChildElement

        private static dynamic CreateChildElement(XElement parent)
        {
            if (parent.Attributes().Count() == 0 && parent.Elements().Count() == 0)
                return null;

            IDictionary<string, object> child = new ExpandoObject();

            parent.Attributes().ToList().ForEach(attr =>
            {
                child.Add(attr.Name.LocalName, attr.Value);

                if (!child.ContainsKey("NodeName"))
                    child.Add("NodeName", attr.Parent.Name.LocalName);
            });

            parent.Elements().ToList().ForEach(childElement =>
            {
                var grandChild = CreateChildElement(childElement);

                if (grandChild != null)
                {
                    string nodeName = grandChild.NodeName;
                    if (child.ContainsKey(nodeName) && child[nodeName].GetType() != typeof(List<dynamic>))
                    {
                        var firstValue = child[nodeName];
                        child[nodeName] = new List<dynamic>();
                        ((dynamic)child[nodeName]).Add(firstValue);
                        ((dynamic)child[nodeName]).Add(grandChild);
                    }
                    else if (child.ContainsKey(nodeName) && child[nodeName].GetType() == typeof(List<dynamic>))
                    {
                        ((dynamic)child[nodeName]).Add(grandChild);
                    }
                    else
                    {
                        child.Add(childElement.Name.LocalName, CreateChildElement(childElement));
                        if (!child.ContainsKey("NodeName"))
                            child.Add("NodeName", parent.Name.LocalName);
                    }
                }
                else
                {
                    child.Add(childElement.Name.LocalName, childElement.Value);
                    if (!child.ContainsKey("NodeName"))
                        child.Add("NodeName", parent.Name.LocalName);
                }
            });

            return child;
        }
開發者ID:oliveiraa,項目名稱:XmlToObjectParser,代碼行數:50,代碼來源:DynamicXmlParser.cs

示例11: KevinBaconItem

        public KevinBaconItem(XElement element)
        {
            _actorName = element.Attributes("name").First().Value + " (" + element.Elements("link").Count() + ")";
            _description = element.Attributes("name").First().Value;
            var links = element.Elements("link").Select(linkElement => " to " + linkElement.Attributes("actor").First().Value
                                                           + " in " + linkElement.Attributes("movie").First().Value);
            _description += "\r\n";
            foreach (var link in links)
            {
                _description += "\r\n" + link;
            }

            _description += "\r\n";
        }
開發者ID:mcwatt77,項目名稱:vimcontrols,代碼行數:14,代碼來源:KevinBaconItem.cs

示例12: PendingUpdate

        public PendingUpdate(XElement updateXml)
        {
            var rawVersion = updateXml
                   .Attributes("NewVersion")
                   .Select(a => a.Value)
                   .FirstOrDefault();

            NewVersion = new Version(rawVersion);

            var rawUpdateFileUri = updateXml
                   .Attributes("UpdateFileUri")
                   .Select(a => a.Value)
                   .FirstOrDefault();

            UpdateFileUri = new Uri(rawUpdateFileUri);

            var rawInfoFileUri = updateXml
                   .Attributes("UpdateInfoUri")
                   .Select(a => a.Value)
                   .FirstOrDefault();

            if (rawInfoFileUri != null)
            {
                UpdateInfoUri = new Uri(rawInfoFileUri);
            }

            var rawCategories = updateXml
                   .Attributes("Categories")
                   .Select(a => a.Value)
                   .FirstOrDefault();

            Categories = rawCategories == null
                ? new List<string>()
                : new List<string>(rawCategories.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));

            InstallFileName = updateXml
                   .Attributes("InstallFileName")
                   .Select(a => a.Value)
                   .FirstOrDefault();

            var descriptionNode = updateXml
                .Elements("Description")
                .FirstOrDefault();

            if (descriptionNode != null)
            {
                Description = descriptionNode.Value;
            }
        }
開發者ID:Phaiax,項目名稱:dotnetautoupdate,代碼行數:49,代碼來源:PendingUpdate.cs

示例13: CreateFieldRefOperand

        public IOperand CreateFieldRefOperand(XElement el)
        {
            if (el == null)
            {
                throw new ArgumentNullException("el");
            }
            Guid? id = null;
            var idAttr = el.Attributes().FirstOrDefault(a => a.Name == Attributes.ID);
            if (idAttr != null)
            {
                try
                {
                    id = new Guid(idAttr.Value);
                }
                catch
                {
                    throw new CamlAnalysisException(string.Format("Value '{0}' is not correct for attribute '{1}'", idAttr.Value, Attributes.ID));
                }
            }

            string name = null;
            var nameAttr = el.Attributes().FirstOrDefault(a => a.Name == Attributes.Name);
            if (nameAttr != null)
            {
                name = nameAttr.Value;
            }

            if (id != null && !string.IsNullOrEmpty(name))
            {
                throw new CamlAnalysisException(string.Format("Only one from two attributes should be specified: {0} or {1}", Attributes.ID, Attributes.Name));
            }

            if (id == null && string.IsNullOrEmpty(name))
            {
                throw new CamlAnalysisException(string.Format("At least one from two attributes should be specified: {0} or {1}", Attributes.ID, Attributes.Name));
            }

            var attributes = el.Attributes().Where(
                attr =>
                {
                    return (attr.Name != Attributes.ID && attr.Name != Attributes.Name &&
                            !string.IsNullOrEmpty(attr.Value));
                })
                    .Select(attr => new KeyValuePair<string, string>(attr.Name.ToString(), attr.Value))
                    .ToList();

            return (id != null ? new FieldRefOperand(id.Value, attributes) : new FieldRefOperand(name, attributes));
        }
開發者ID:chutinhha,項目名稱:tvmcorptvs,代碼行數:48,代碼來源:ReOperandBuilderFromCaml.cs

示例14: LoadMPD

        public static MPD LoadMPD(XElement element)
        {
            var ns = element.GetDefaultNamespace().NamespaceName;
            var result = new MPD();

            result.Id = (string)element.Attribute("id");
            result.Profiles = (string)element.Attribute("profiles");
            result.Type = element.Attribute("type").GetEnum<Presentation>();
            result.AvailabilityStartTime = element.Attribute("availabilityStartTime").GetNullableDateTime();
            result.AvailabilityEndTime = element.Attribute("availabilityEndTime").GetNullableDateTime();
            result.MediaPresentationDuration = element.Attribute("mediaPresentationDuration").GetNullableDuration();
            result.MinimumUpdatePeriod = element.Attribute("minimumUpdatePeriod").GetNullableDuration();
            result.MinBufferTime = element.Attribute("minBufferTime").GetNullableDuration();
            result.TimeShiftBufferDepth = element.Attribute("timeShiftBufferDepth").GetNullableDuration();
            result.SuggestedPresentationDelay = element.Attribute("suggestedPresentationDelay").GetNullableDuration();
            result.MaxSegmentDuration = element.Attribute("maxSegmentDuration").GetNullableDuration();
            result.MaxSubsegmentDuration = element.Attribute("maxSubsegmentDuration").GetNullableDuration();
            result.AnyAttr.AddRange(element.Attributes());

            result.ProgramInformation.AddRange(element.Elements(XName.Get("ProgramInformation", ns)).Select(LoadProgramInformation));
            result.BaseURL.AddRange(element.Elements(XName.Get("BaseURL", ns)).Select(LoadBaseURL));
            result.Location.AddRange(element.Elements(XName.Get("Location", ns)).Select(e => e.Value));
            result.Period.AddRange(element.Elements(XName.Get("Period", ns)).Select(LoadPeriod));
            result.Metrics.AddRange(element.Elements(XName.Get("Metrics", ns)).Select(LoadMetrics));
            result.Any.AddRange(element.Elements());

            return result;
        }
開發者ID:bondarenkod,項目名稱:pf-arm-deploy-error,代碼行數:28,代碼來源:MPDFactory.cs

示例15: HasIncludePath

        private static bool HasIncludePath(XElement includeElement, string includePath)
        {
            XAttribute attr;
            attr = includeElement.Attributes(PathAttrName).Single();

            return attr != null && string.Equals(attr.Value, includePath, StringComparison.OrdinalIgnoreCase);
        }
開發者ID:clintcparker,項目名稱:sonar-msbuild-runner,代碼行數:7,代碼來源:RulesetAssertions.cs


注:本文中的System.Xml.Linq.XElement.Attributes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。