NHibernate Forge
The official new home for the NHibernate for .NET community

ConventionModelMapper & .net 4 ISet<>

Wiki Page Hierarchy

Pages

Page Details

First published by:
ashern
on 07-14-2011
Last revision by:
ashern
on 07-14-2011
1 person found this article useful.
Article
Comments (2)
History (3)
100% of people found this useful

ConventionModelMapper & .net 4 ISet<>

For anyone using José's Net4CollectionTypeFactory to enable native ISet<> usage, here's how to get the convention mapper to recognize your ISet<> properties as type Set rather than Bag (code courtesy JFR):

In your mapping

mapper.IsSet(IsSetFieldType);

Function implementation

private static bool IsSetFieldType(MemberInfo mi, bool declared)
        {
            var propertyTypeIsSet = mi.GetPropertyOrFieldType()
                .GetGenericInterfaceTypeDefinitions()
                .Contains(typeof(ISet<>));
 
            if (propertyTypeIsSet) return true;
 
            var backFieldInfo = PropertyToField.GetBackFieldInfo((PropertyInfo)mi);
 
            return backFieldInfo != null
                   && backFieldInfo
                          .FieldType.GetGenericInterfaceTypeDefinitions().Contains(typeof(ISet<>));
        }
Remember to add the collection type factory to your config..

configuration.CollectionTypeFactory<Net4CollectionTypeFactory>();

Recent Comments

By: rgmoon Posted on 08-07-2011 6:21

It is always important for me to get the info regarding different software, their applications and usage. This post is providing us a lot info regarding these software. Thanks for such nice and brilliant addition. Keep providing us info regarding different software in the coming posts.

www.city32.com/.../169_Oconto_County_Reporter.html

By: davido Posted on 08-04-2011 21:41

Thanks for sharing this article.I have been looking for this piece of code for a long time.I have been working in a .net domian for over 5 years now but was really struggling to find the modelmapper code.Also,i was wondering whether we can use .net code on www.bluelock.com/.../vcloudconnector ,since vcloud is the future of technology.PLease let me know on how to use .net in vcloud.

View All
Powered by Community Server (Commercial Edition), by Telligent Systems