/// <inheritdoc/>
        public bool ShouldApply(ICollectionMappingProvider target)
        {
            var propertyType = target.PropertyInfo.PropertyType;

            return((target.StoreAs == StoreAs.Undefined) && ((propertyType.IsArray) || ((propertyType.GetTypeInfo().IsGenericType) &&
                                                                                        (propertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>) || (propertyType.GetGenericTypeDefinition() == typeof(ICollection <>))))));
        }
Ejemplo n.º 2
0
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
     if (collectionMappingProvider.StoreAs == Model.StoreAs.RdfList)
     {
         _entryMaps.Add(CreateListOwnerMapping(collectionMappingProvider));
         _entryMaps.Add(CreateListEntryMapping(collectionMappingProvider));
     }
 }
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
     if (collectionMappingProvider.StoreAs == Model.StoreAs.RdfList)
     {
         _entryMaps.Add(CreateListOwnerMapping(collectionMappingProvider));
         _entryMaps.Add(CreateListEntryMapping(collectionMappingProvider));
     }
 }
        /// <inheritdoc/>
        public bool ShouldApply(ICollectionMappingProvider target)
        {
            var propertyType = target.PropertyInfo.PropertyType;

            return (target.StoreAs == StoreAs.Undefined) && propertyType.IsGenericType
                   && (propertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>)
                      || propertyType.GetGenericTypeDefinition() == typeof(ICollection<>));
        }
        private EntityMap CreateListOwnerMapping(ICollectionMappingProvider map)
        {
            var defineDynamicModule = EmitHelper.GetDynamicModule("DynamicListMappings");
            var ownerTypeName = GetOwnerTypeName(map);

            var mapType = defineDynamicModule.GetOrEmitType(ownerTypeName + "Map", moduleBuilder => EmitOwnerMappingType(map, moduleBuilder, ownerTypeName));
            return (EntityMap)Activator.CreateInstance(mapType);
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public void Visit(ICollectionMappingProvider collectionMappingProvider)
        {
            if (collectionMappingProvider == null)
            {
                throw new ArgumentNullException(nameof(collectionMappingProvider));
            }

            if (collectionMappingProvider.StoreAs == CollectionStorageModel.Unspecified)
            {
                collectionMappingProvider.StoreAs = GetStorageModel(collectionMappingProvider.Property.PropertyType);
            }
        }
Ejemplo n.º 7
0
        private TypeBuilder EmitNodeMappingType(ModuleBuilder builder, ICollectionMappingProvider map, string nodeTypeName)
        {
            var elementType = map.PropertyInfo.PropertyType.FindItemType();
            var nodeType    = builder.DefineType(
                nodeTypeName,
                TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract,
                null,
                new[] { typeof(IRdfListNode <>).MakeGenericType(elementType) }).CreateTypeInfo().AsType();
            var converterType = map.ElementConverterType ?? map.ConverterType;
            var ownerMapType  = typeof(ListEntryMap <, ,>).MakeGenericType(nodeType, elementType, converterType);

            return(builder.DefineType(nodeTypeName + "Map", TypeAttributes.Public, ownerMapType));
        }
Ejemplo n.º 8
0
        private EntityMap CreateListEntryMapping(ICollectionMappingProvider map)
        {
            Type mapType             = null;
            var  defineDynamicModule = _emitHelper.GetDynamicModule();
            var  nodeTypeName        = GetNodeTypeName(map);

            lock (defineDynamicModule)
            {
                mapType = defineDynamicModule.GetOrEmitType(nodeTypeName + "Map", builder => EmitNodeMappingType(builder, map, nodeTypeName));
            }

            return((EntityMap)Activator.CreateInstance(mapType));
        }
Ejemplo n.º 9
0
        private EntityMap CreateListOwnerMapping(ICollectionMappingProvider map)
        {
            Type mapType             = null;
            var  defineDynamicModule = _emitHelper.GetDynamicModule();
            var  ownerTypeName       = GetOwnerTypeName(map);

            lock (defineDynamicModule)
            {
                mapType = defineDynamicModule.GetOrEmitType(ownerTypeName + "Map", moduleBuilder => EmitOwnerMappingType(map, moduleBuilder, ownerTypeName));
            }

            return((EntityMap)Activator.CreateInstance(mapType));
        }
Ejemplo n.º 10
0
 internal static CollectionMapping CreateFrom(
     IEntityMapping entityMapping,
     ICollectionMappingProvider collectionMappingProvider,
     IConverter valueConverter,
     IEnumerable <QIriMapping> qiriMappings)
 {
     return(new CollectionMapping(
                entityMapping,
                collectionMappingProvider.Property,
                collectionMappingProvider.GetGraph(qiriMappings),
                collectionMappingProvider.GetTerm(qiriMappings),
                valueConverter,
                collectionMappingProvider.StoreAs));
 }
        private CollectionMapping BuildCollectionMapping(ICollectionMappingProvider provider)
        {
            var collectionMapping = new CollectionMapping(
                provider.PropertyInfo.DeclaringType,
                provider.PropertyInfo.PropertyType,
                provider.PropertyInfo.Name,
                provider.GetTerm(_mappingContext.OntologyProvider),
                provider.StoreAs);
            bool converterSet = SetConverter(collectionMapping, provider);
            if ((provider.ElementConverterType != null) && (!provider.ElementConverterType.ContainsGenericParameters))
            {
                collectionMapping.ElementConverter = (INodeConverter)Activator.CreateInstance(provider.ElementConverterType);
            }
            else if (converterSet)
            {
                collectionMapping.ElementConverter = collectionMapping.Converter;
            }

            return collectionMapping;
        }
Ejemplo n.º 12
0
        private CollectionMapping BuildCollectionMapping(ICollectionMappingProvider provider)
        {
            var collectionMapping = new CollectionMapping(
                provider.PropertyInfo.DeclaringType,
                provider.PropertyInfo.PropertyType,
                provider.PropertyInfo.Name,
                provider.GetTerm(_mappingContext.OntologyProvider),
                provider.StoreAs);
            bool converterSet = SetConverter(collectionMapping, provider);

            if ((provider.ElementConverterType != null) && (!provider.ElementConverterType.GetTypeInfo().ContainsGenericParameters))
            {
                collectionMapping.ElementConverter = _converterCatalog.GetConverter(provider.ElementConverterType);
            }
            else if (converterSet)
            {
                collectionMapping.ElementConverter = collectionMapping.Converter;
            }

            return(collectionMapping);
        }
 /// <inheritdoc/>
 public void Apply(ICollectionMappingProvider target)
 {
     target.StoreAs = StoreAs.RdfList;
 }
 /// <inheritdoc/>
 public bool ShouldApply(ICollectionMappingProvider target)
 {
     return target.StoreAs == StoreAs.Undefined
         && target.PropertyInfo.PropertyType.IsGenericType
         && target.PropertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(IList<>);
 }
Ejemplo n.º 15
0
 /// <inheritdoc />
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
     Visit((IPropertyMappingProvider)collectionMappingProvider);
 }
Ejemplo n.º 16
0
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
     PropertyMappingProviders.Add(new CollectionMapping(collectionMappingProvider, _currentEntityMapping.EntityType.MakeGenericType(_genricArguments).FindProperty(collectionMappingProvider.PropertyInfo.Name)));
 }
Ejemplo n.º 17
0
 public CollectionMapping(ICollectionMappingProvider openGeneric, PropertyInfo property) : base(openGeneric, property)
 {
     _openGeneric = openGeneric;
 }
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
 }
 /// <inheritdoc/>
 public void Apply(ICollectionMappingProvider target)
 {
     target.StoreAs = StoreAs.SimpleCollection;
 }
 public CollectionMapping(ICollectionMappingProvider openGeneric, PropertyInfo property)
     : base(openGeneric, property)
 {
     _openGeneric = openGeneric;
 }
Ejemplo n.º 21
0
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 22
0
 /// <inheritdoc/>
 public void Apply(ICollectionMappingProvider target)
 {
     target.StoreAs = StoreAs.RdfList;
 }
        private EntityMap CreateListEntryMapping(ICollectionMappingProvider map)
        {
            var defineDynamicModule = EmitHelper.GetDynamicModule("DynamicListMappings");
            var nodeTypeName = GetNodeTypeName(map);

            var mapType = defineDynamicModule.GetOrEmitType(nodeTypeName + "Map", builder => EmitNodeMappingType(builder, map, nodeTypeName));

            return (EntityMap)Activator.CreateInstance(mapType);
        }
 internal ClosedGenericCollectionMappingProvider(Type closedGenericType, ICollectionMappingProvider openGenericCollectionMappingProvider)
     : base(closedGenericType, openGenericCollectionMappingProvider)
 {
     _openGenericCollectionMappingProvider = openGenericCollectionMappingProvider;
 }
 /// <inheritdoc/>
 public void Apply(ICollectionMappingProvider target)
 {
     target.StoreAs = StoreAs.SimpleCollection;
 }
        private TypeBuilder EmitNodeMappingType(ModuleBuilder builder, ICollectionMappingProvider map, string nodeTypeName)
        {
            var elementType = map.PropertyInfo.PropertyType.FindItemType();
            var nodeType = builder.DefineType(
                   nodeTypeName,
                   TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract,
                   null,
                   new[] { typeof(IRdfListNode<>).MakeGenericType(elementType) }).CreateType();
            var converterType = map.ElementConverterType ?? map.ConverterType;
            var ownerMapType = typeof(ListEntryMap<,,>).MakeGenericType(nodeType, elementType, converterType);

            return builder.DefineType(nodeTypeName + "Map", TypeAttributes.Public, ownerMapType);
        }
 private string GetNodeTypeName(ICollectionMappingProvider map)
 {
     return string.Format("{0}_{1}_ListNode", _currentEntityType.FullName, map.PropertyInfo.Name);
 }
Ejemplo n.º 28
0
 /// <inheritdoc/>
 bool IConvention <ICollectionMappingProvider> .ShouldApply(ICollectionMappingProvider target)
 {
     return((target.StoreAs == StoreAs.RdfList) && (target.ElementConverterType == null) && (GetConverterType(target.PropertyInfo.PropertyType.FindItemType()) != null));
 }
Ejemplo n.º 29
0
 /// <inheritdoc/>
 void IConvention <ICollectionMappingProvider> .Apply(ICollectionMappingProvider target)
 {
     target.ElementConverterType = GetConverterType(target.PropertyInfo.PropertyType.FindItemType());
 }
Ejemplo n.º 30
0
 private string GetNodeTypeName(ICollectionMappingProvider map)
 {
     return(string.Format("{0}_{1}_ListNode", _currentEntityType.FullName, map.PropertyInfo.Name));
 }
Ejemplo n.º 31
0
 /// <inheritdoc/>
 public bool ShouldApply(ICollectionMappingProvider target)
 {
     return(target.StoreAs == StoreAs.Undefined &&
            target.PropertyInfo.PropertyType.GetTypeInfo().IsGenericType &&
            target.PropertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(IList <>));
 }
 /// <summary>
 /// Validates the specified collection mapping provider.
 /// </summary>
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
     Visit(collectionMappingProvider as IPropertyMappingProvider);
 }
Ejemplo n.º 33
0
 internal CollectionMappingProvider(Type entityType, ICollectionMappingProvider parentCollectionMappingProvider)
 {
     EntityType = entityType;
     _parentCollectionMappingProvider = parentCollectionMappingProvider;
 }
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
 }
Ejemplo n.º 35
0
 /// <summary>Applies property and collection conventions to <paramref name="collectionMappingProvider"/>.</summary>
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
     SelectAndApplyConventions <ICollectionConvention, ICollectionMappingProvider>(collectionMappingProvider);
     Visit(collectionMappingProvider as IPropertyMappingProvider);
 }
 public void Visit(ICollectionMappingProvider collectionMappingProvider)
 {
     PropertyMappingProviders.Add(new CollectionMapping(collectionMappingProvider, _currentEntityMapping.EntityType.MakeGenericType(_genricArguments).FindProperty(collectionMappingProvider.PropertyInfo.Name)));
 }