当你的才华不能撑起你的野心时,就是你该选择学习的时候了!

c# XElement linq filter

using System.Xml;

using System.Xml.Linq;

 

       // 调用

static private void InitIncrementalSanctionsReferencesList(this XmlReader reader, PFA pfa)

        {

            XElement xEl = XElement.ReadFrom(reader) as XElement;

           if (xEl != null)

            {

               var sanctionsReferencesElements = from el in xEl.Elements().Where(q => ListTypeFilter(q.GetAttributeValue("name"), this.ListType) == true) select el;

           }

        }

 

       // 定义

       static bool ListTypeFilter(string hand, List<string> filters) => filters.Any(filter => hand.Contains(filter));

 

       static private string GetAttributeValue(this XElement ele, string xname)

        {

           var attr = ele.Attribute(xname);

           if (attr != null)

                return attr.Value.Trim();

           return string.Empty;

        }

 

static public List<string> ListType { get { return new List<string> { "EC ", "EU ", "UN ", "UK " }; } }

 

posted @ 2022-08-30 17:27  hofmann  阅读(56)  评论(0)    收藏  举报