Skip to content

Instantly share code, notes, and snippets.

@jahands
Last active August 29, 2015 14:16
Show Gist options
  • Save jahands/85f51ca9ebcd8f739426 to your computer and use it in GitHub Desktop.
Save jahands/85f51ca9ebcd8f739426 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Imflow.Utilities;
namespace Imflow.Data.Entity.Configurations
{
internal delegate void ConfigurationDelegate
(Type modelType, EntityTypeConfiguration<dynamic> entity);
class DefaultInterfaceConfiguration
{
private static List<ConfigTypeMap> _configurations = new List<ConfigTypeMap>();
static DefaultInterfaceConfiguration()
{
_configurations.Add(new ConfigTypeMap(typeof(IPerson), ConfigureIPerson(null, null)));
}
private static ConfigurationDelegate ConfigureIPerson
(Type modelType, EntityTypeConfiguration<dynamic> entity )
{
dynamic configType = entity;
ConfigureIPerson(configType);
return null;
}
public static void ConfigureAny<T>
(EntityTypeConfiguration<T> entity, Type modelType) where T : class
{
foreach (Type type in modelType.GetInterfaces())
{
dynamic configType = entity;
}
}
private static void ConfigureIPerson<T>
(EntityTypeConfiguration<T> entity) where T : class, IPerson, new()
{
entity.Property(t => t.FirstName).HasMaxLength(15);
}
}
}
namespace Imflow.Data.Entity.Configurations
{
class ConfigTypeMap
{
public ConfigTypeMap() { }
public ConfigTypeMap(Type modelType)
{
ModelType = modelType;
}
public ConfigTypeMap(Type modelType, ConfigurationDelegate configurationDelegate)
{
ModelType = modelType;
ConfigurationDelegate = configurationDelegate;
}
public Type ModelType { get; set; }
public ConfigurationDelegate ConfigurationDelegate { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment