Пример #1
0
        public static TDictionary ParseDictionary <TDictionary, TKey, TValue, TNode>(XmlNode owner, XmlNamespaceManager manager, IEnumerable <Tuple <string, IEnumerable <string> > > pluralSingleDetails, Func <PluralSingleExtraDetail <TNode>, TValue> valueSelector, Func <PluralSingleExtraDetail <Tuple <TNode, TValue> >, TKey> keySelector)
            where TDictionary :
        IDictionary <TKey, TValue>,
        new()
            where TNode :
        XmlNode
        {
            TDictionary result = new TDictionary();

            foreach (var psDetail in pluralSingleDetails)
            {
                var psdCurrent = new PluralSingleDetail()
                {
                    Plural = psDetail.Item1
                };
                var targetNode = owner;
                if (!string.IsNullOrEmpty(psdCurrent.Plural))
                {
                    targetNode = targetNode.SelectSingleNode(string.Format("./vre:{0}", psdCurrent.Plural), manager);
                }
                if (targetNode == null)
                {
                    continue;
                }
                foreach (var detail in psDetail.Item2)
                {
                    psdCurrent.Single = detail;
                    XmlNodeList xnl = targetNode.SelectNodes(string.Format("./vre:{0}", psdCurrent.Single), manager);
                    foreach (TNode node in from node in xnl.Cast <XmlNode>()
                             where node is TNode
                             select(TNode) node)
                    {
                        var value = valueSelector(new PluralSingleExtraDetail <TNode>(psdCurrent)
                        {
                            Extra = node
                        });
                        var key = keySelector(new PluralSingleExtraDetail <Tuple <TNode, TValue> >(psdCurrent)
                        {
                            Extra = Tuple.Create(node, value)
                        });
                        result.Add(key, value);
                    }
                }
            }
            return(result);
        }
Пример #2
0
 public PluralSingleExtraDetail(PluralSingleDetail detail)
 {
     this.Plural = detail.Plural;
     this.Single = detail.Single;
 }