/// <inheritdoc/> bool IConvention <IDictionaryMappingProvider> .ShouldApply(IDictionaryMappingProvider target) { var keyType = target.PropertyInfo.PropertyType.GenericTypeArguments[0]; var valueType = target.PropertyInfo.PropertyType.GenericTypeArguments[1]; return((target.Key.ConverterType == null && (GetConverterType(keyType.FindItemType()) != null)) || (target.Value.ConverterType == null && (GetConverterType(valueType.FindItemType()) != null))); }
private PropertyMapping BuildDictionaryMapping(IDictionaryMappingProvider provider) { var dictionaryMapping = new DictionaryMapping( provider.PropertyInfo.DeclaringType, provider.PropertyInfo.PropertyType, provider.PropertyInfo.Name, provider.GetTerm(_mappingContext.OntologyProvider), provider.Key.GetTerm(_mappingContext.OntologyProvider), provider.Value.GetTerm(_mappingContext.OntologyProvider)); SetConverter(dictionaryMapping, provider); return dictionaryMapping; }
/// <inheritdoc/> void IConvention <IDictionaryMappingProvider> .Apply(IDictionaryMappingProvider target) { if (target.Key.ConverterType == null) { target.Key.ConverterType = GetConverterType(target.PropertyInfo.PropertyType.GenericTypeArguments[0].FindItemType()); } if (target.Value.ConverterType == null) { target.Value.ConverterType = GetConverterType(target.PropertyInfo.PropertyType.GenericTypeArguments[1].FindItemType()); } }
private PropertyMapping BuildDictionaryMapping(IDictionaryMappingProvider provider) { var dictionaryMapping = new DictionaryMapping( provider.PropertyInfo.DeclaringType, provider.PropertyInfo.PropertyType, provider.PropertyInfo.Name, provider.GetTerm(_mappingContext.OntologyProvider), provider.Key.GetTerm(_mappingContext.OntologyProvider), provider.Value.GetTerm(_mappingContext.OntologyProvider)); SetConverter(dictionaryMapping, provider); return(dictionaryMapping); }
private EntityMap CreateDictionaryOwnerMapping(IDictionaryMappingProvider map) { // todo: refactoring var actualEntityType = map.PropertyInfo.DeclaringType; var owner = actualEntityType.Assembly.GetType(string.Format("{0}_{1}_Owner", actualEntityType.FullName, map.PropertyInfo.Name)); var entry = actualEntityType.Assembly.GetType(string.Format("{0}_{1}_Entry", actualEntityType.FullName, map.PropertyInfo.Name)); var type = typeof(DictionaryOwnerMap<,,,>); var typeArguments = new[] { owner, entry }.Concat(map.PropertyInfo.PropertyType.GenericTypeArguments).ToArray(); var ownerMapType = type.MakeGenericType(typeArguments); var defineDynamicModule = EmitHelper.GetDynamicModule("DynamicDictionaryMappings"); var mapType = defineDynamicModule.GetOrEmitType(owner.Name + "Map", builder => EmitOwnerMap(map, builder, owner, ownerMapType)); return (EntityMap)Activator.CreateInstance(mapType); }
private EntityMap CreateDictionaryEntryMapping(IDictionaryMappingProvider map) { var entry = GetOrCreateDictionaryEntryType(map.PropertyInfo); var type = typeof(DictionaryEntryMap <, ,>); var typeArguments = new[] { entry }.Concat(map.PropertyInfo.PropertyType.GenericTypeArguments).ToArray(); var ownerMapType = type.MakeGenericType(typeArguments); var defineDynamicModule = _emitHelper.GetDynamicModule(); Type mapType; lock (defineDynamicModule) { mapType = defineDynamicModule.GetOrEmitType(entry.Name + "Map", builder => EmitEntryMap(map, builder, entry, ownerMapType)); } return((EntityMap)Activator.CreateInstance(mapType)); }
private TypeBuilder EmitOwnerMap(IDictionaryMappingProvider map, ModuleBuilder defineDynamicModule, Type owner, Type ownerMapType) { var typeBuilderHelper = defineDynamicModule.DefineType(owner.Name + "Map", TypeAttributes.Public, ownerMapType); var methodBuilderHelper = typeBuilderHelper.DefineMethod( "SetupEntriesCollection", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, typeof(void), new[] { typeof(ITermPart<ICollectionMap>) }); var ilGenerator = methodBuilderHelper.GetILGenerator(); ilGenerator.Emit(OpCodes.Nop); ilGenerator.Emit(OpCodes.Ldarg_1); ilGenerator.Emit(OpCodes.Ldstr, map.GetTerm(_ontologyProvider).ToString()); ilGenerator.Emit(OpCodes.Newobj, typeof(Uri).GetConstructor(new[] { typeof(string) })); ilGenerator.Emit(OpCodes.Callvirt, typeof(ITermPart<CollectionMap>).GetMethod("Is", new Type[] { typeof(Uri) })); ilGenerator.Emit(OpCodes.Pop); ilGenerator.Emit(OpCodes.Ret); return typeBuilderHelper; }
private TypeBuilder EmitOwnerMap(IDictionaryMappingProvider map, ModuleBuilder defineDynamicModule, Type owner, Type ownerMapType) { var typeBuilderHelper = defineDynamicModule.DefineType(owner.Name + "Map", TypeAttributes.Public, ownerMapType); var methodBuilderHelper = typeBuilderHelper.DefineMethod( "SetupEntriesCollection", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, typeof(void), new[] { typeof(ITermPart <ICollectionMap>) }); var ilGenerator = methodBuilderHelper.GetILGenerator(); ilGenerator.Emit(OpCodes.Nop); ilGenerator.Emit(OpCodes.Ldarg_1); ilGenerator.Emit(OpCodes.Ldstr, map.GetTerm(_ontologyProvider).ToString()); ilGenerator.Emit(OpCodes.Newobj, typeof(Uri).GetConstructor(new[] { typeof(string) })); ilGenerator.Emit(OpCodes.Callvirt, typeof(ITermPart <CollectionMap>).GetMethod("Is", new Type[] { typeof(Uri) })); ilGenerator.Emit(OpCodes.Pop); ilGenerator.Emit(OpCodes.Ret); return(typeBuilderHelper); }
private TypeBuilder EmitEntryMap(IDictionaryMappingProvider map, ModuleBuilder defineDynamicModule, Type entry, Type ownerMapType) { var typeBuilderHelper = defineDynamicModule.DefineType(entry.Name + "Map", TypeAttributes.Public, ownerMapType); var setupKeyMethod = typeBuilderHelper.DefineMethod( "SetupKeyProperty", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, typeof(void), new[] { typeof(ITermPart <IPropertyMap>) }); EmitSetupPropertyOverride(setupKeyMethod, map.Key); var setupValueMethod = typeBuilderHelper.DefineMethod( "SetupValueProperty", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, typeof(void), new[] { typeof(ITermPart <IPropertyMap>) }); EmitSetupPropertyOverride(setupValueMethod, map.Value); return(typeBuilderHelper); }
/// <summary>Sets the key predicate to <see cref="Rdf.@object"/>.</summary> public void Apply(IDictionaryMappingProvider target) { target.Value.GetTerm = provider => Rdf.@object; }
public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { _entityMaps.Add(CreateDictionaryOwnerMapping(dictionaryMappingProvider)); _entityMaps.Add(CreateDictionaryEntryMapping(dictionaryMappingProvider)); }
public DictionaryMapping(IDictionaryMappingProvider openGeneric, PropertyInfo property) : base(openGeneric, property) { _openGeneric = openGeneric; }
public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { throw new NotImplementedException(); }
/// <inheritdoc/> /// <returns>true if <see cref="IDictionaryMappingProvider.Value"/> doesn't map to a URI</returns> public bool ShouldApply(IDictionaryMappingProvider target) { return target.Value.GetTerm == null; }
public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { }
public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { PropertyMappingProviders.Add(new DictionaryMapping(dictionaryMappingProvider, _currentEntityMapping.EntityType.MakeGenericType(_genricArguments).FindProperty(dictionaryMappingProvider.PropertyInfo.Name))); }
public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { _entityMaps.Add(CreateDictionaryOwnerMapping(dictionaryMappingProvider)); _entityMaps.Add(CreateDictionaryEntryMapping(dictionaryMappingProvider)); }
/// <summary>Validates the specified dictionary mapping provider.</summary> public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { Visit(dictionaryMappingProvider as IPropertyMappingProvider); AssertTermMapped(dictionaryMappingProvider.Key, string.Format("{0}.Key", dictionaryMappingProvider)); AssertTermMapped(dictionaryMappingProvider.Value, string.Format("{0}.Value", dictionaryMappingProvider)); }
/// <summary> /// Sets the key predicate to <see cref="Rdf.predicate"/> /// </summary> public void Apply(IDictionaryMappingProvider target) { target.Key.GetTerm = provider => Rdf.predicate; }
public DictionaryMapping(IDictionaryMappingProvider openGeneric, PropertyInfo property) : base(openGeneric, property) { _openGeneric = openGeneric; }
/// <inheritdoc/> /// <returns>true if <see cref="IDictionaryMappingProvider.Key"/> doesn't map to a URI</returns> public bool ShouldApply(IDictionaryMappingProvider target) { return(target.Key.GetTerm == null); }
public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { }
/// <summary>Sets the key predicate to <see cref="Rdf.predicate"/>.</summary> public void Apply(IDictionaryMappingProvider target) { target.Key.GetTerm = provider => Rdf.predicate; }
/// <summary> /// Sets the key predicate to <see cref="Rdf.@object"/> /// </summary> public void Apply(IDictionaryMappingProvider target) { target.Value.GetTerm = provider => Rdf.@object; }
/// <summary> /// Validates the specified dictionary mapping provider. /// </summary> public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { Visit(dictionaryMappingProvider as IPropertyMappingProvider); AssertTermMapped(dictionaryMappingProvider.Key, string.Format("{0}.Key", dictionaryMappingProvider)); AssertTermMapped(dictionaryMappingProvider.Value, string.Format("{0}.Value", dictionaryMappingProvider)); }
/// <summary>Applies property and dictionary conventions to <paramref name="dictionaryMappingProvider"/>.</summary> public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { SelectAndApplyConventions <IDictionaryConvention, IDictionaryMappingProvider>(dictionaryMappingProvider); Visit(dictionaryMappingProvider as IPropertyMappingProvider); }
public void Visit(IDictionaryMappingProvider dictionaryMappingProvider) { PropertyMappingProviders.Add(new DictionaryMapping(dictionaryMappingProvider, _currentEntityMapping.EntityType.MakeGenericType(_genricArguments).FindProperty(dictionaryMappingProvider.PropertyInfo.Name))); }