This commit is contained in:
25
DynamORM.sln
25
DynamORM.sln
@@ -29,6 +29,18 @@ Global
|
|||||||
{63963ED7-9C78-4672-A4D4-339B6E825503}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
{63963ED7-9C78-4672-A4D4-339B6E825503}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
{63963ED7-9C78-4672-A4D4-339B6E825503}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
{63963ED7-9C78-4672-A4D4-339B6E825503}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
{63963ED7-9C78-4672-A4D4-339B6E825503}.Release|x86.ActiveCfg = Release|Any CPU
|
{63963ED7-9C78-4672-A4D4-339B6E825503}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Any CPU.Build.0 = Debug|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Any CPU.ActiveCfg = Release|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Any CPU.Build.0 = Release|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.Build.0 = Release|x86
|
||||||
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
@@ -39,16 +51,6 @@ Global
|
|||||||
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||||
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||||
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|x86.ActiveCfg = Release|Any CPU
|
{D5013B4E-8A1B-4DBB-8FB5-E09935F4F764}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Any CPU.ActiveCfg = Debug|x86
|
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|x86.ActiveCfg = Debug|x86
|
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Debug|x86.Build.0 = Debug|x86
|
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Any CPU.ActiveCfg = Release|x86
|
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|Mixed Platforms.Build.0 = Release|x86
|
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.ActiveCfg = Release|x86
|
|
||||||
{A64D2052-D0CD-488E-BF05-E5952615D926}.Release|x86.Build.0 = Release|x86
|
|
||||||
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Any CPU.ActiveCfg = Debug|x86
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||||
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||||
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||||
@@ -60,6 +62,9 @@ Global
|
|||||||
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|x86.ActiveCfg = Release|x86
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|x86.ActiveCfg = Release|x86
|
||||||
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|x86.Build.0 = Release|x86
|
{F747AA57-BEA7-4FB8-B371-546296789AEF}.Release|x86.Build.0 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(MonoDevelopProperties) = preSolution
|
||||||
|
StartupItem = AmalgamationTool\AmalgamationTool.csproj
|
||||||
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
|||||||
@@ -29,6 +29,10 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
|
<RegisterForComInterop>False</RegisterForComInterop>
|
||||||
|
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||||
|
<BaseAddress>4194304</BaseAddress>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>PdbOnly</DebugType>
|
<DebugType>PdbOnly</DebugType>
|
||||||
@@ -38,9 +42,12 @@
|
|||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||||
<DebugSymbols>false</DebugSymbols>
|
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
<DocumentationFile>bin\Release\DynamORM.xml</DocumentationFile>
|
<DocumentationFile>bin\Release\DynamORM.xml</DocumentationFile>
|
||||||
|
<RegisterForComInterop>False</RegisterForComInterop>
|
||||||
|
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
|
||||||
|
<BaseAddress>4194304</BaseAddress>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
|
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
|
||||||
<RegisterForComInterop>False</RegisterForComInterop>
|
<RegisterForComInterop>False</RegisterForComInterop>
|
||||||
|
|||||||
@@ -67,7 +67,9 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
k => k.Value.Name,
|
k => k.Value.Name,
|
||||||
v => v.Value);
|
v => v.Value);
|
||||||
|
|
||||||
_methods = GetAllMembers(_type)
|
_methods = mapper.MethodsMap;
|
||||||
|
|
||||||
|
/*GetAllMembers(_type)
|
||||||
.Where(x => x is MethodInfo)
|
.Where(x => x is MethodInfo)
|
||||||
.Cast<MethodInfo>()
|
.Cast<MethodInfo>()
|
||||||
.Where(m => !((m.Name.StartsWith("set_") && m.ReturnType == typeof(void)) || m.Name.StartsWith("get_")))
|
.Where(m => !((m.Name.StartsWith("set_") && m.ReturnType == typeof(void)) || m.Name.StartsWith("get_")))
|
||||||
@@ -84,7 +86,7 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Provides implementation for type conversion operations.
|
/// <summary>Provides implementation for type conversion operations.
|
||||||
@@ -236,7 +238,7 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
|
|
||||||
if (d != null)
|
if (d != null)
|
||||||
{
|
{
|
||||||
result = d.DynamicInvoke(CompleteArguments(mi.GetParameters().ToArray(), args));
|
result = d.DynamicInvoke(CompleteArguments(mi.GetParameters().ToArray(), args).ToArray());
|
||||||
|
|
||||||
if (d.Method.ReturnType == _type && result is T)
|
if (d.Method.ReturnType == _type && result is T)
|
||||||
result = new DynamicProxy<T>((T)result);
|
result = new DynamicProxy<T>((T)result);
|
||||||
@@ -245,7 +247,7 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
}
|
}
|
||||||
else if (mi != null)
|
else if (mi != null)
|
||||||
{
|
{
|
||||||
result = mi.Invoke(_proxy, CompleteArguments(mi.GetParameters().ToArray(), args));
|
result = mi.Invoke(_proxy, CompleteArguments(mi.GetParameters().ToArray(), args).Skip(1).ToArray());
|
||||||
|
|
||||||
if (mi.ReturnType == _type && result is T)
|
if (mi.ReturnType == _type && result is T)
|
||||||
result = new DynamicProxy<T>((T)result);
|
result = new DynamicProxy<T>((T)result);
|
||||||
@@ -268,9 +270,9 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private object[] CompleteArguments(ParameterInfo[] parameters, object[] arguments)
|
private IEnumerable<object> CompleteArguments(ParameterInfo[] parameters, object[] arguments)
|
||||||
{
|
{
|
||||||
return arguments.Concat(parameters.Skip(arguments.Length).Select(p => p.DefaultValue)).ToArray();
|
return new object[] { _proxy }.Union(arguments.Concat(parameters.Skip(arguments.Length).Select(p => p.DefaultValue)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<MemberInfo> GetAllMembers(Type type)
|
private IEnumerable<MemberInfo> GetAllMembers(Type type)
|
||||||
@@ -320,7 +322,6 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
object res;
|
object res;
|
||||||
TryInvokeMethod("Dispose", out res, new object[] { });
|
TryInvokeMethod("Dispose", out res, new object[] { });
|
||||||
|
|
||||||
_methods.Clear();
|
|
||||||
_properties.Clear();
|
_properties.Clear();
|
||||||
|
|
||||||
_methods = null;
|
_methods = null;
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ namespace DynamORM.Mapper
|
|||||||
/// <summary>Represents type columnMap.</summary>
|
/// <summary>Represents type columnMap.</summary>
|
||||||
public class DynamicTypeMap
|
public class DynamicTypeMap
|
||||||
{
|
{
|
||||||
|
private Dictionary<MethodInfo, Delegate> _methods = null;
|
||||||
|
|
||||||
/// <summary>Gets mapper destination type creator.</summary>
|
/// <summary>Gets mapper destination type creator.</summary>
|
||||||
public Type Type { get; private set; }
|
public Type Type { get; private set; }
|
||||||
|
|
||||||
@@ -50,6 +52,17 @@ namespace DynamORM.Mapper
|
|||||||
/// <remarks>Key: Column name (lower), Value: <see cref="DynamicPropertyInvoker"/>.</remarks>
|
/// <remarks>Key: Column name (lower), Value: <see cref="DynamicPropertyInvoker"/>.</remarks>
|
||||||
public Dictionary<string, DynamicPropertyInvoker> ColumnsMap { get; private set; }
|
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>
|
/// <summary>Gets map of properties to column.</summary>
|
||||||
/// <remarks>Key: Property name, Value: Column name.</remarks>
|
/// <remarks>Key: Property name, Value: Column name.</remarks>
|
||||||
public Dictionary<string, string> PropertyMap { get; private set; }
|
public Dictionary<string, string> PropertyMap { get; private set; }
|
||||||
@@ -72,6 +85,29 @@ namespace DynamORM.Mapper
|
|||||||
CreateColumnAndPropertyMap();
|
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()
|
private void CreateColumnAndPropertyMap()
|
||||||
{
|
{
|
||||||
var columnMap = new Dictionary<string, DynamicPropertyInvoker>();
|
var columnMap = new Dictionary<string, DynamicPropertyInvoker>();
|
||||||
|
|||||||
Reference in New Issue
Block a user