Example #1
0
        public IList GetNonGenericCollectionProperty(XElement field)
        {
            var l = new ArrayList();

            foreach (var arrayValueNode in field.Elements())
            {
                l.Add(valueParser.Parse(arrayValueNode, typeof(object)));
            }
            return(l);
        }
Example #2
0
        public void Visit(object doc, string fieldName, XElement field)
        {
            var            allFields = mapper.GetFields(doc.GetType());
            SolrFieldModel thisField;

            if (!allFields.TryGetValue(fieldName, out thisField))
            {
                return;
            }
            if (!thisField.Property.CanWrite)
            {
                return;
            }
            if (parser.CanHandleSolrType(field.Name.LocalName) &&
                parser.CanHandleType(thisField.Property.PropertyType))
            {
                var v = parser.Parse(field, thisField.Property.PropertyType);
                try
                {
                    thisField.Property.SetValue(doc, v, null);
                }
                catch (ArgumentException e)
                {
                    throw new ArgumentException(string.Format("Could not convert value '{0}' to property '{1}' of document type {2}", v, thisField.Property.Name, thisField.Property.DeclaringType), e);
                }
            }
        }
Example #3
0
 public object Parse(XElement field, Type t)
 {
     if (string.IsNullOrEmpty(field.Value) && TypeHelper.IsNullableType(t))
     {
         return(null);
     }
     return(parser.Parse(field, t));
 }
Example #4
0
        public Dictionary <string, object> ParseDocument(XElement node)
        {
            var doc = new Dictionary <string, object>();

            foreach (var field in node.Elements())
            {
                var fieldName = field.Attribute("name").Value;
                doc[fieldName] = fieldParser.Parse(field, typeof(object));
            }
            return(doc);
        }
Example #5
0
        public void Visit(object doc, string fieldName, XElement field)
        {
            var allFields = mapper.GetFields(doc.GetType());
            var thisField = allFields.FirstOrDefault(p => p.FieldName == fieldName);

            if (thisField == null)
            {
                return;
            }
            if (!thisField.Property.CanWrite)
            {
                return;
            }
            if (parser.CanHandleSolrType(field.Name.LocalName) &&
                parser.CanHandleType(thisField.Property.PropertyType))
            {
                var v = parser.Parse(field, thisField.Property.PropertyType);
                thisField.Property.SetValue(doc, v, null);
            }
        }
Example #6
0
        public void Visit(object doc, string fieldName, XElement field)
        {
            var thisField = memoGetThisField(doc.GetType(), fieldName);

            if (thisField == null)
            {
                return;
            }
            var thisFieldName = thisField.FieldName;
            //if (!field.Attributes["name"].InnerText.StartsWith(thisFieldName))
            //    return;
            var typeArgs  = thisField.Property.PropertyType.GetGenericArguments();
            var keyType   = typeArgs[0];
            var valueType = typeArgs[1];
            var dict      = thisField.Property.GetValue(doc, null) ?? NewDictionary(typeArgs);
            var key       = GetKeyToUse(field.Attribute("name").Value, thisFieldName);
            var value     = parser.Parse(field, valueType);

            SetKV(dict, ConvertTo(key, keyType), value);
            thisField.Property.SetValue(doc, dict, null);
        }
        public object Parse(XElement field, Type t)
        {
            var type = solrTypes[field.Name.LocalName];

            return(parser.Parse(field, type));
        }