This commit is contained in:
@@ -91,13 +91,13 @@ namespace DynamORM.Helpers
|
||||
int firstCount;
|
||||
int secondCount;
|
||||
|
||||
var firstElementCounts = GetElementCounts(first, out firstCount);
|
||||
var secondElementCounts = GetElementCounts(second, out secondCount);
|
||||
Dictionary<T, int> firstElementCounts = GetElementCounts(first, out firstCount);
|
||||
Dictionary<T, int> secondElementCounts = GetElementCounts(second, out secondCount);
|
||||
|
||||
if (firstCount != secondCount)
|
||||
return true;
|
||||
|
||||
foreach (var kvp in firstElementCounts)
|
||||
foreach (KeyValuePair<T, int> kvp in firstElementCounts)
|
||||
if (kvp.Value != (secondElementCounts.TryGetNullable(kvp.Key) ?? 0))
|
||||
return true;
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace DynamORM.Helpers
|
||||
|
||||
private static Dictionary<T, int> GetElementCounts(IEnumerable<T> enumerable, out int nullCount)
|
||||
{
|
||||
var dictionary = new Dictionary<T, int>();
|
||||
Dictionary<T, int> dictionary = new Dictionary<T, int>();
|
||||
nullCount = 0;
|
||||
|
||||
foreach (T element in enumerable)
|
||||
|
||||
@@ -33,6 +33,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
@@ -77,12 +78,12 @@ namespace DynamORM.Helpers.Dynamics
|
||||
// Func was cool but caused memory leaks
|
||||
private DynamicMetaObject GetBinder(Node node)
|
||||
{
|
||||
var o = (Node)this.Value;
|
||||
Node o = (Node)this.Value;
|
||||
node.Parser = o.Parser;
|
||||
o.Parser.Last = node;
|
||||
|
||||
var p = Expression.Variable(typeof(Node), "ret");
|
||||
var exp = Expression.Block(new ParameterExpression[] { p }, Expression.Assign(p, Expression.Constant(node)));
|
||||
ParameterExpression p = Expression.Variable(typeof(Node), "ret");
|
||||
BlockExpression exp = Expression.Block(new ParameterExpression[] { p }, Expression.Assign(p, Expression.Constant(node)));
|
||||
|
||||
return new MetaNode(exp, this.Restrictions, node);
|
||||
}
|
||||
@@ -187,8 +188,8 @@ namespace DynamORM.Helpers.Dynamics
|
||||
/// </returns>
|
||||
public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
|
||||
{
|
||||
var o = (Node)this.Value;
|
||||
var node = new Unary(o, binder.Operation) { Parser = o.Parser };
|
||||
Node o = (Node)this.Value;
|
||||
Unary node = new Unary(o, binder.Operation) { Parser = o.Parser };
|
||||
o.Parser.Last = node;
|
||||
|
||||
// If operation is 'IsTrue' or 'IsFalse', we will return false to keep the engine working...
|
||||
@@ -196,8 +197,8 @@ namespace DynamORM.Helpers.Dynamics
|
||||
if (binder.Operation == ExpressionType.IsTrue) ret = (object)false;
|
||||
if (binder.Operation == ExpressionType.IsFalse) ret = (object)false;
|
||||
|
||||
var p = Expression.Variable(ret.GetType(), "ret"); // the type is now obtained from "ret"
|
||||
var exp = Expression.Block(
|
||||
ParameterExpression p = Expression.Variable(ret.GetType(), "ret"); // the type is now obtained from "ret"
|
||||
BlockExpression exp = Expression.Block(
|
||||
new ParameterExpression[] { p },
|
||||
Expression.Assign(p, Expression.Constant(ret))); // the expression is now obtained from "ret"
|
||||
|
||||
@@ -213,8 +214,8 @@ namespace DynamORM.Helpers.Dynamics
|
||||
/// </returns>
|
||||
public override DynamicMetaObject BindConvert(ConvertBinder binder)
|
||||
{
|
||||
var o = (Node)this.Value;
|
||||
var node = new Convert(o, binder.ReturnType) { Parser = o.Parser };
|
||||
Node o = (Node)this.Value;
|
||||
Convert node = new Convert(o, binder.ReturnType) { Parser = o.Parser };
|
||||
o.Parser.Last = node;
|
||||
|
||||
// Reducing the object to return if this is an assignment node...
|
||||
@@ -249,8 +250,8 @@ namespace DynamORM.Helpers.Dynamics
|
||||
}
|
||||
}
|
||||
|
||||
var p = Expression.Variable(binder.ReturnType, "ret");
|
||||
var exp = Expression.Block(
|
||||
ParameterExpression p = Expression.Variable(binder.ReturnType, "ret");
|
||||
BlockExpression exp = Expression.Block(
|
||||
new ParameterExpression[] { p },
|
||||
Expression.Assign(p, Expression.Constant(ret, binder.ReturnType))); // specifying binder.ReturnType
|
||||
|
||||
@@ -1102,7 +1103,7 @@ namespace DynamORM.Helpers.Dynamics
|
||||
if (!IsDisposed && _arguments != null)
|
||||
list.AddRange(_arguments);
|
||||
|
||||
foreach (var arg in list)
|
||||
foreach (Node.Argument arg in list)
|
||||
yield return arg;
|
||||
|
||||
list.Clear();
|
||||
@@ -1134,13 +1135,13 @@ namespace DynamORM.Helpers.Dynamics
|
||||
{
|
||||
// I know this can be almost a one liner
|
||||
// but it causes memory leaks when so.
|
||||
var pars = f.Method.GetParameters();
|
||||
foreach (var p in pars)
|
||||
ParameterInfo[] pars = f.Method.GetParameters();
|
||||
foreach (ParameterInfo p in pars)
|
||||
{
|
||||
var attrs = p.GetCustomAttributes(typeof(DynamicAttribute), true).Length;
|
||||
int attrs = p.GetCustomAttributes(typeof(DynamicAttribute), true).Length;
|
||||
if (attrs != 0)
|
||||
{
|
||||
var par = new Node.Argument(p.Name) { Parser = this };
|
||||
Node.Argument par = new Node.Argument(p.Name) { Parser = this };
|
||||
this._arguments.Add(par);
|
||||
}
|
||||
else
|
||||
@@ -1176,7 +1177,7 @@ namespace DynamORM.Helpers.Dynamics
|
||||
|
||||
if (_arguments != null)
|
||||
{
|
||||
foreach (var arg in _arguments)
|
||||
foreach (Node.Argument arg in _arguments)
|
||||
{
|
||||
if (!first) sb.Append(", "); else first = false;
|
||||
sb.Append(arg);
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace DynamORM.Helpers.Dynamics
|
||||
_proxy = proxiedObject;
|
||||
_type = typeof(T);
|
||||
|
||||
var mapper = Mapper.DynamicMapperCache.GetMapper<T>();
|
||||
DynamicTypeMap mapper = Mapper.DynamicMapperCache.GetMapper<T>();
|
||||
|
||||
_properties = mapper
|
||||
.ColumnsMap
|
||||
@@ -146,7 +146,7 @@ namespace DynamORM.Helpers.Dynamics
|
||||
{
|
||||
try
|
||||
{
|
||||
var prop = _properties.TryGetValue(binder.Name);
|
||||
DynamicPropertyInvoker prop = _properties.TryGetValue(binder.Name);
|
||||
|
||||
result = prop.NullOr(p => p.Get.NullOr(g => g(_proxy), null), null);
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace DynamORM.Helpers.Dynamics
|
||||
{
|
||||
try
|
||||
{
|
||||
var prop = _properties.TryGetValue(binder.Name);
|
||||
DynamicPropertyInvoker prop = _properties.TryGetValue(binder.Name);
|
||||
|
||||
if (prop != null && prop.Setter != null)
|
||||
{
|
||||
@@ -278,18 +278,17 @@ namespace DynamORM.Helpers.Dynamics
|
||||
{
|
||||
if (type.IsInterface)
|
||||
{
|
||||
var members = new List<MemberInfo>();
|
||||
|
||||
var considered = new List<Type>();
|
||||
var queue = new Queue<Type>();
|
||||
List<MemberInfo> members = new List<MemberInfo>();
|
||||
List<Type> considered = new List<Type>();
|
||||
Queue<Type> queue = new Queue<Type>();
|
||||
|
||||
considered.Add(type);
|
||||
queue.Enqueue(type);
|
||||
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var subType = queue.Dequeue();
|
||||
foreach (var subInterface in subType.GetInterfaces())
|
||||
Type subType = queue.Dequeue();
|
||||
foreach (Type subInterface in subType.GetInterfaces())
|
||||
{
|
||||
if (considered.Contains(subInterface)) continue;
|
||||
|
||||
@@ -297,12 +296,12 @@ namespace DynamORM.Helpers.Dynamics
|
||||
queue.Enqueue(subInterface);
|
||||
}
|
||||
|
||||
var typeProperties = subType.GetMembers(
|
||||
MemberInfo[] typeProperties = subType.GetMembers(
|
||||
BindingFlags.FlattenHierarchy
|
||||
| BindingFlags.Public
|
||||
| BindingFlags.Instance);
|
||||
|
||||
var newPropertyInfos = typeProperties
|
||||
IEnumerable<MemberInfo> newPropertyInfos = typeProperties
|
||||
.Where(x => !members.Contains(x));
|
||||
|
||||
members.InsertRange(0, newPropertyInfos);
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace DynamORM.Helpers
|
||||
// HACK: Creating binders assuming types are correct... this may fail.
|
||||
if (IsMono)
|
||||
{
|
||||
var binderType = typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).Assembly.GetType("Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder");
|
||||
Type binderType = typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).Assembly.GetType("Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder");
|
||||
|
||||
if (binderType != null)
|
||||
{
|
||||
@@ -76,16 +76,16 @@ namespace DynamORM.Helpers
|
||||
}
|
||||
else
|
||||
{
|
||||
var inter = typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).Assembly.GetType("Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder");
|
||||
Type inter = typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).Assembly.GetType("Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder");
|
||||
|
||||
if (inter != null)
|
||||
{
|
||||
var prop = inter.GetProperty("TypeArguments");
|
||||
PropertyInfo prop = inter.GetProperty("TypeArguments");
|
||||
|
||||
if (!prop.CanRead)
|
||||
return null;
|
||||
|
||||
var objParm = Expression.Parameter(typeof(InvokeMemberBinder), "o");
|
||||
ParameterExpression objParm = Expression.Parameter(typeof(InvokeMemberBinder), "o");
|
||||
|
||||
return Expression.Lambda<Func<InvokeMemberBinder, IList<Type>>>(
|
||||
Expression.TypeAs(
|
||||
@@ -121,7 +121,7 @@ namespace DynamORM.Helpers
|
||||
// In mono this is trivial.
|
||||
|
||||
// First we get field info.
|
||||
var field = binder.GetType().GetField("typeArguments", BindingFlags.Instance |
|
||||
FieldInfo field = binder.GetType().GetField("typeArguments", BindingFlags.Instance |
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
// If this was a success get and return it's value
|
||||
@@ -134,12 +134,12 @@ namespace DynamORM.Helpers
|
||||
// In this case, we need more aerobic :D
|
||||
|
||||
// First, get the interface
|
||||
var inter = binder.GetType().GetInterface("Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder");
|
||||
Type inter = binder.GetType().GetInterface("Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder");
|
||||
|
||||
if (inter != null)
|
||||
{
|
||||
// Now get property.
|
||||
var prop = inter.GetProperty("TypeArguments");
|
||||
PropertyInfo prop = inter.GetProperty("TypeArguments");
|
||||
|
||||
// If we have a property, return it's value
|
||||
if (prop != null)
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace DynamORM.Helpers
|
||||
|
||||
if (props.Length != 0)
|
||||
{
|
||||
foreach (var prop in props)
|
||||
foreach (PropertyInfo prop in props)
|
||||
{
|
||||
if (!first) sb.Append(", "); else first = false;
|
||||
sb.AppendFormat("{0}='{1}'", prop.Name, prop.GetValue(obj, null).Sketch());
|
||||
@@ -156,7 +156,7 @@ namespace DynamORM.Helpers
|
||||
{
|
||||
if (infos.Length != 0)
|
||||
{
|
||||
foreach (var info in infos)
|
||||
foreach (FieldInfo info in infos)
|
||||
{
|
||||
if (!first) sb.Append(", "); else first = false;
|
||||
sb.AppendFormat("{0}='{1}'", info.Name, info.GetValue(obj).Sketch());
|
||||
|
||||
Reference in New Issue
Block a user