// ReSharper disable once UnusedMember.Local
        private static IClrCollectionAccessor CreateGeneric <TEntity, TCollection, TElement>(PropertyInfo property)
            where TCollection : class, ICollection <TElement>
        {
            var getterDelegate = (Func <TEntity, TCollection>)property.GetMethod.CreateDelegate(typeof(Func <TEntity, TCollection>));

            Action <TEntity, TCollection> setterDelegate = null;
            Func <TEntity, Action <TEntity, TCollection>, TCollection> createAndSetDelegate = null;

            var setter = property.SetMethod;

            if (setter != null)
            {
                setterDelegate = (Action <TEntity, TCollection>)setter.CreateDelegate(typeof(Action <TEntity, TCollection>));

                var concreteType = new CollectionTypeFactory().TryFindTypeToInstantiate(typeof(TCollection));

                if (concreteType != null)
                {
                    createAndSetDelegate = (Func <TEntity, Action <TEntity, TCollection>, TCollection>)_createAndSet
                                           .MakeGenericMethod(typeof(TEntity), typeof(TCollection), concreteType)
                                           .CreateDelegate(typeof(Func <TEntity, Action <TEntity, TCollection>, TCollection>));
                }
            }

            return(new ClrICollectionAccessor <TEntity, TCollection, TElement>(
                       property.Name, getterDelegate, setterDelegate, createAndSetDelegate));
        }
Exemplo n.º 2
0
        public ClrCollectionAccessorSource([NotNull] CollectionTypeFactory collectionTypeFactory)
        {
            Check.NotNull(collectionTypeFactory, "collectionTypeFactory");

            _collectionTypeFactory = collectionTypeFactory;
        }