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); } } }
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); } }
public bool CanHandleType(Type t) { return(parser.CanHandleType(t) || parser.CanHandleType(TypeHelper.GetUnderlyingNullableType(t))); }