This commit is contained in:
grzegorz.russek
2014-11-27 22:04:43 +00:00
parent efb03643d1
commit 10a22759eb
4 changed files with 67 additions and 18 deletions

View File

@@ -37,6 +37,8 @@ namespace DynamORM.Mapper
/// <summary>Represents type columnMap.</summary>
public class DynamicTypeMap
{
private Dictionary<MethodInfo, Delegate> _methods = null;
/// <summary>Gets mapper destination type creator.</summary>
public Type Type { get; private set; }
@@ -50,6 +52,17 @@ namespace DynamORM.Mapper
/// <remarks>Key: Column name (lower), Value: <see cref="DynamicPropertyInvoker"/>.</remarks>
public Dictionary<string, DynamicPropertyInvoker> ColumnsMap { get; private set; }
/// <summary>Gets map of methods to open instance delegates.</summary>
public Dictionary<MethodInfo, Delegate> MethodsMap
{
get
{
if (_methods == null)
_methods = CreateMethodToDelegateMap();
return _methods;
}
}
/// <summary>Gets map of properties to column.</summary>
/// <remarks>Key: Property name, Value: Column name.</remarks>
public Dictionary<string, string> PropertyMap { get; private set; }
@@ -72,6 +85,29 @@ namespace DynamORM.Mapper
CreateColumnAndPropertyMap();
}
private Dictionary<MethodInfo, Delegate> CreateMethodToDelegateMap()
{
return GetAllMembers(Type)
.Where(x => x is MethodInfo)
.Cast<MethodInfo>()
.Where(m => !((m.Name.StartsWith("set_") && m.ReturnType == typeof(void)) || m.Name.StartsWith("get_")))
.Where(m => !m.IsStatic && !m.IsGenericMethod)
.ToDictionary(
k => k,
v =>
{
try
{
return Delegate.CreateDelegate(Expression.GetDelegateType(new Type[] { v.DeclaringType }.Union(v.GetParameters().Select(t => t.ParameterType).Concat(new[] { v.ReflectedType })).ToArray()), v);
////return Delegate.CreateDelegate(Expression.GetDelegateType(v.GetParameters().Select(t => t.ParameterType).Concat(new[] { v.ReflectedType }).ToArray()), _proxy, v.Name);
}
catch (ArgumentException)
{
return null;
}
});
}
private void CreateColumnAndPropertyMap()
{
var columnMap = new Dictionary<string, DynamicPropertyInvoker>();