Пример #1
0
        protected override void ReadDocumentFields <TElement>(Dictionary <string, object> document, IEnumerable <string> fieldNames, DocumentTypeMapInfo documentTypeMapInfo, IEnumerable <IFieldQueryTranslator> virtualFieldProcessors, TElement result)
        {
            Assert.ArgumentNotNull(document, "document");
            Assert.ArgumentNotNull(documentTypeMapInfo, "documentTypeMapInfo");
            Assert.ArgumentNotNull(result, "result");

            if (virtualFieldProcessors != null)
            {
                Func <Dictionary <string, object>, IFieldQueryTranslator, Dictionary <string, object> > func =
                    (current, processor) =>
                    (Dictionary <string, object>)processor.TranslateFieldResult(current, index.FieldNameTranslator);
                document = virtualFieldProcessors.Aggregate(document, func);
            }

            if (index.FieldNameTranslator != null)
            {
                foreach (var pair in index.FieldNameTranslator.MapDocumentFieldsToType(result.GetType(), fieldNames))
                {
                    object obj2 = null;
                    if (document.ContainsKey(pair.Key))
                    {
                        obj2 = document[pair.Key];
                    }
                    var key = pair.Key;
                    foreach (var str2 in pair.Value)
                    {
                        documentTypeMapInfo.SetProperty(result, str2, key, obj2);
                    }
                }
            }
            else
            {
                foreach (var pair2 in document)
                {
                    documentTypeMapInfo.SetProperty(result, pair2.Key, pair2.Key, pair2.Value);
                }
            }
        }
Пример #2
0
 protected override void ReadDocumentFields <TElement>(XmlNode document, IEnumerable <string> fieldNames, DocumentTypeMapInfo documentTypeMapInfo, IEnumerable <IFieldQueryTranslator> virtualFieldProcessors, TElement result)
 {
     if (fieldNames != null)
     {
         //
         //get values stored in field tags
         var mapping = base.index.FieldNameTranslator.MapDocumentFieldsToType(result.GetType(), fieldNames);
         foreach (var pair in mapping)
         {
             var fieldNode = document.SelectSingleNode(string.Format("field[@name='{0}']", pair.Key));
             if (fieldNode != null)
             {
                 foreach (var name in pair.Value)
                 {
                     documentTypeMapInfo.SetProperty(result, name, pair.Key, fieldNode.InnerText);
                 }
             }
         }
         //
         //get values stored in attributes
         var nameAttribute = document.Attributes["name"];
         if (nameAttribute != null)
         {
             documentTypeMapInfo.SetProperty(result, "name", "name", nameAttribute.Value);
         }
         var pathAttribute = document.Attributes["path"];
         if (pathAttribute != null)
         {
             documentTypeMapInfo.SetProperty(result, "path", "path", pathAttribute.Value);
         }
         var idAttribute = document.Attributes["id"];
         if (idAttribute != null)
         {
             documentTypeMapInfo.SetProperty(result, "id", "id", idAttribute.Value);
         }
     }
 }