public static ObjectExtensionManager AddOrUpdateProperty <TObject, TProperty>(
     [NotNull] this ObjectExtensionManager objectExtensionManager,
     [NotNull] string propertyName,
     [CanBeNull] Action <ObjectExtensionPropertyInfo> configureAction = null)
     where TObject : IHasExtraProperties
 {
     return(objectExtensionManager.AddOrUpdateProperty(
                typeof(TObject),
                typeof(TProperty),
                propertyName,
                configureAction
                ));
 }
Exemple #2
0
 public static ObjectExtensionManager MapEfCoreProperty <TEntity, TProperty>(
     [NotNull] this ObjectExtensionManager objectExtensionManager,
     [NotNull] string propertyName,
     [CanBeNull] Action <EntityTypeBuilder, PropertyBuilder> entityTypeAndPropertyBuildAction)
     where TEntity : IHasExtraProperties, IEntity
 {
     return(objectExtensionManager.MapEfCoreProperty(
                typeof(TEntity),
                typeof(TProperty),
                propertyName,
                entityTypeAndPropertyBuildAction
                ));
 }
Exemple #3
0
        public static ObjectExtensionPropertyInfo GetPropertyOrNull(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] Type objectType,
            [NotNull] string propertyName)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
            Check.NotNull(objectType, nameof(objectType));
            Check.NotNull(propertyName, nameof(propertyName));

            return(objectExtensionManager
                   .GetOrNull(objectType)?
                   .GetPropertyOrNull(propertyName));
        }
Exemple #4
0
        public static ObjectExtensionManager MapEfCoreEntity(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] Type entityType,
            [NotNull] Action <EntityTypeBuilder> entityTypeBuildAction)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));

            return(objectExtensionManager.AddOrUpdate(
                       entityType,
                       options =>
            {
                options.MapEfCoreEntity(entityTypeBuildAction);
            }));
        }
Exemple #5
0
        public static ObjectExtensionManager MapEfCoreProperty(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] Type entityType,
            [NotNull] Type propertyType,
            [NotNull] string propertyName)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));

            return(objectExtensionManager.AddOrUpdateProperty(
                       entityType,
                       propertyType,
                       propertyName,
                       options => { options.MapEfCore(); }
                       ));
        }
Exemple #6
0
        public static ImmutableList <ObjectExtensionPropertyInfo> GetProperties(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] Type objectType)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
            Check.NotNull(objectType, nameof(objectType));

            var extensionInfo = objectExtensionManager.GetOrNull(objectType);

            if (extensionInfo == null)
            {
                return(EmptyPropertyList);
            }

            return(extensionInfo.GetProperties());
        }
Exemple #7
0
        public static void ConfigureEfCoreEntity(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] EntityTypeBuilder typeBuilder)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
            Check.NotNull(typeBuilder, nameof(typeBuilder));

            var objectExtension = objectExtensionManager.GetOrNull(typeBuilder.Metadata.ClrType);

            if (objectExtension == null)
            {
                return;
            }

            var efCoreEntityMappings = objectExtension.GetEfCoreEntityMappings();

            foreach (var efCoreEntityMapping in efCoreEntityMappings)
            {
                efCoreEntityMapping.EntityTypeBuildAction?.Invoke(typeBuilder);
            }

            foreach (var property in objectExtension.GetProperties())
            {
                var efCoreMapping = property.GetEfCoreMappingOrNull();
                if (efCoreMapping == null)
                {
                    continue;
                }

                /* Prevent multiple calls to the entityTypeBuilder.Property(...) method */
                if (typeBuilder.Metadata.FindProperty(property.Name) != null)
                {
                    continue;
                }

                var propertyBuilder = typeBuilder.Property(property.Type, property.Name);

                efCoreMapping.EntityTypeAndPropertyBuildAction?.Invoke(typeBuilder, propertyBuilder);
#pragma warning disable 618
                efCoreMapping.PropertyBuildAction?.Invoke(propertyBuilder);
#pragma warning restore 618
            }
        }
        public static ObjectExtensionManager AddOrUpdateProperty(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] Type objectType,
            [NotNull] Type propertyType,
            [NotNull] string propertyName,
            [CanBeNull] Action <ObjectExtensionPropertyInfo> configureAction = null)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));

            return(objectExtensionManager.AddOrUpdate(
                       objectType,
                       options =>
            {
                options.AddOrUpdateProperty(
                    propertyType,
                    propertyName,
                    configureAction
                    );
            }));
        }
Exemple #9
0
        public static ObjectExtensionManager MapEfCoreProperty(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] Type entityType,
            [NotNull] Type propertyType,
            [NotNull] string propertyName,
            [CanBeNull] Action <EntityTypeBuilder, PropertyBuilder> entityTypeAndPropertyBuildAction)
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));

            return(objectExtensionManager.AddOrUpdateProperty(
                       entityType,
                       propertyType,
                       propertyName,
                       options =>
            {
                options.MapEfCore(
                    entityTypeAndPropertyBuildAction
                    );
            }
                       ));
        }
        public static ObjectExtensionManager AddOrUpdateProperty(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] Type[] objectTypes,
            [NotNull] Type propertyType,
            [NotNull] string propertyName,
            [CanBeNull] Action <ObjectExtensionPropertyInfo> configureAction = null)
        {
            Check.NotNull(objectTypes, nameof(objectTypes));

            foreach (var objectType in objectTypes)
            {
                objectExtensionManager.AddOrUpdateProperty(
                    objectType,
                    propertyType,
                    propertyName,
                    configureAction
                    );
            }

            return(objectExtensionManager);
        }
Exemple #11
0
        public static void ConfigureEfCoreDbContext <TDbContext>(
            [NotNull] this ObjectExtensionManager objectExtensionManager,
            [NotNull] ModelBuilder modelBuilder)
            where TDbContext : DbContext
        {
            Check.NotNull(objectExtensionManager, nameof(objectExtensionManager));
            Check.NotNull(modelBuilder, nameof(modelBuilder));

            var objectExtension = objectExtensionManager.GetOrNull(typeof(TDbContext));

            if (objectExtension == null)
            {
                return;
            }

            var efCoreDbContextMappings = objectExtension.GetEfCoreDbContextMappings();

            foreach (var efCoreDbContextMapping in efCoreDbContextMappings)
            {
                efCoreDbContextMapping.ModelBuildAction?.Invoke(modelBuilder);
            }
        }
 public ObjectExtensionManager_Tests()
 {
     _objectExtensionManager = new ObjectExtensionManager();
 }
Exemple #13
0
 public static ImmutableList <ObjectExtensionPropertyInfo> GetProperties <TObject>(
     [NotNull] this ObjectExtensionManager objectExtensionManager)
 {
     return(objectExtensionManager.GetProperties(typeof(TObject)));
 }