public static CollectionType GenericSet(string role, string propertyRef, System.Type elementClass)
        {
            MethodInfo mi = ReflectHelper.GetGenericMethodFrom <ICollectionTypeFactory>("Set", new[] { elementClass },
                                                                                        GenericCollectionSimpleSignature);

            return((CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new object[] { role, propertyRef, false }));
        }
        public static CollectionType GenericSortedSet(string role, string propertyRef, object comparer,
                                                      System.Type elementClass)
        {
            var        signature = new[] { typeof(string), typeof(string), typeof(bool), typeof(IComparer <>).MakeGenericType(elementClass) };
            MethodInfo mi        = ReflectHelper.GetGenericMethodFrom <ICollectionTypeFactory>("SortedSet", new[] { elementClass },
                                                                                               signature);

            return((CollectionType)mi.Invoke(Instance.CollectionTypeFactory, new object[] { role, propertyRef, false, comparer }));
        }
        public void GetGenericMethodFrom()
        {
            var signature = new[] { typeof(string), typeof(string), typeof(bool) };

            Assert.That(ReflectHelper.GetGenericMethodFrom <ISomething>("List", new[] { typeof(BRhf) }, signature), Is.Not.Null);
            Assert.That(ReflectHelper.GetGenericMethodFrom <ISomething>("List", new[] { typeof(int), typeof(string) }, signature), Is.Not.Null);
            Assert.That(ReflectHelper.GetGenericMethodFrom <ISomething>("List", new[] { typeof(int), typeof(string) }
                                                                        , new[] { typeof(string), typeof(string), typeof(bool), typeof(IComparer <>).MakeGenericType(typeof(int)) }), Is.Not.Null);
        }
Esempio n. 4
0
        public void GetGenericMethodFrom()
        {
            var signature = new[] { typeof(string), typeof(string), typeof(bool) };

            // This is the fixture for this obsolete member, so disable the obsolete warning.
#pragma warning disable CS0618 // Type or member is obsolete
            Assert.That(ReflectHelper.GetGenericMethodFrom <ISomething>("List", new[] { typeof(BRhf) }, signature), Is.Not.Null);
            Assert.That(ReflectHelper.GetGenericMethodFrom <ISomething>("List", new[] { typeof(int), typeof(string) }, signature), Is.Not.Null);
            Assert.That(ReflectHelper.GetGenericMethodFrom <ISomething>("List", new[] { typeof(int), typeof(string) }
                                                                        , new[] { typeof(string), typeof(string), typeof(bool), typeof(IComparer <>).MakeGenericType(typeof(int)) }), Is.Not.Null);
#pragma warning restore CS0618 // Type or member is obsolete
        }
        private void addMapper(CommonCollectionMapperData commonCollectionMapperData, MiddleComponentData elementComponentData, MiddleComponentData indexComponentData)
        {
            var propertyValueType = _propertyValue.GetType();
            var type = _propertyValue.Type;
            var embeddableElementType = isEmbeddableElementType();

            IPropertyMapper collectionMapper;
            var             collectionProxyMapperFactory = _mainGenerator.GlobalCfg.CollectionMapperFactory;

            if (_propertyAuditingData.CustomCollectionMapperFactory != null)
            {
                collectionMapper = _propertyAuditingData.CustomCollectionMapperFactory.Create(_mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, embeddableElementType);
            }
            else if (propertyValueType == typeof(Set))
            {
                if (_propertyValue.IsSorted)
                {
                    var comparerType = createGenericComparerType(type);
                    var methodInfo   = ReflectHelper.GetGenericMethodFrom <ICollectionMapperFactory>("SortedSet",
                                                                                                     type.ReturnedClass.GetGenericArguments(),
                                                                                                     new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), comparerType, typeof(bool) });
                    collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
                                                                          new[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, _propertyValue.Comparer, embeddableElementType });
                }
                else
                {
                    var methodInfo = ReflectHelper.GetGenericMethodFrom <ICollectionMapperFactory>("Set",
                                                                                                   type.ReturnedClass.GetGenericArguments(),
                                                                                                   new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(bool) });
                    collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
                                                                          new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, embeddableElementType });
                }
            }
            else if (propertyValueType == typeof(List))
            {
                var methodInfo = ReflectHelper.GetGenericMethodFrom <ICollectionMapperFactory>("List",
                                                                                               type.ReturnedClass.GetGenericArguments(),
                                                                                               new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(MiddleComponentData), typeof(bool) });
                collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
                                                                      new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, embeddableElementType });
            }
            else if (propertyValueType == typeof(Map))
            {
                if (_propertyValue.IsSorted)
                {
                    var comparerType = createGenericComparerType(type);
                    var methodInfo   = ReflectHelper.GetGenericMethodFrom <ICollectionMapperFactory>("SortedMap",
                                                                                                     type.ReturnedClass.GetGenericArguments(),
                                                                                                     new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(MiddleComponentData), comparerType, typeof(bool) });
                    collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
                                                                          new[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, _propertyValue.Comparer, embeddableElementType });
                }
                else
                {
                    var methodInfo = ReflectHelper.GetGenericMethodFrom <ICollectionMapperFactory>("Map",
                                                                                                   type.ReturnedClass.GetGenericArguments(),
                                                                                                   new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(MiddleComponentData), typeof(bool) });
                    collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
                                                                          new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, embeddableElementType });
                }
            }
            else if (propertyValueType == typeof(Bag))
            {
                var methodInfo = ReflectHelper.GetGenericMethodFrom <ICollectionMapperFactory>("Bag",
                                                                                               type.ReturnedClass.GetGenericArguments(),
                                                                                               new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(bool) });
                collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
                                                                      new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, embeddableElementType });
            }
            else if (propertyValueType == typeof(IdentifierBag))
            {
                var methodInfo = ReflectHelper.GetGenericMethodFrom <ICollectionMapperFactory>("IdBag",
                                                                                               type.ReturnedClass.GetGenericArguments(),
                                                                                               new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(bool) });
                collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
                                                                      new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, embeddableElementType });
            }
            else
            {
                throw new NotImplementedException("Mapped collection type " + type.Name + " is not currently supported in Envers");
            }
            _currentMapper.AddComposite(_propertyAuditingData.GetPropertyData(), collectionMapper);
        }