Skip to content

Conversation

@khalidsalomao
Copy link
Contributor

Only use CollectionReflectionFieldMapper if no custom type converter was provided.
Since Generic collections are not implemented, this will allow the user to provide his custom converter.

Example:

class sample
{
    public List<string> List { get; set; }
    public Dictionary<string, string> Dic { get; set; }
}

var map = new ClassMap<sample>(Lucene.Net.Util.Version.LUCENE_30);
map.Property(i => i.List).ConvertWith(new CustomListConverter());
map.Property(i => i.Dic).ConvertWith(new CustomDictionaryConverter());

Only use CollectionReflectionFieldMapper if no custom type converter was provided. 
Since Generic collections  not implemented, this will allow the user to provide his custom converter.
@chriseldredge
Copy link
Owner

Some tests would be good here. Does this address #32?

@khalidsalomao
Copy link
Contributor Author

Yes! This is a partial solution for #32.

By partial I mean that the user must provide the TypeConverter, but we will have some support for collections. It is a start!

This weekend, I will add some tests!

@khalidsalomao
Copy link
Contributor Author

There is a problem with my approach (as seen in the failed test).
I was expecting to apply the type converter to the collection instance, but the mapper apply the type converter to each item of the collection.

CollectionReflectionFieldMapper.CopyFromDocument

@chriseldredge, what do you think about adding another attribute AsPrimitive or IsCollection or StoreAsCollection to manage this behavior?

This option would keep the current behavior as default, but would allow a new way of dealing with collections (treat the whole collection instance). This new type conversion behavior is the partial solution for #32.

The use case of this new behavior is to allow Lucene.Net.Linq to store an object that has such collections. It is not perfect, since it won't be very helpful for indexing but at least such objects can be stored... (It is a partial support)

Next week, I will take a look and try submit a new pull request with the full solution for #32. What do you think?

@chriseldredge
Copy link
Owner

I think the extension point should be in CollectionReflectionFieldMapper.

The values.ToArray(elementType) is what needs to be extensible. Perhaps having the option (with attributes or fluent syntax) to specify an alternate helper method that creates an appropriate collection type.

The default converter implementation could also be smarter and try to create an appropriate instance for the property type, supporting commonly used collections like T[], IList<T>, ISet<T>, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants