changeset 3:1ef98bd70424

!bug 100 +3h Исправление проблемы BLToolkit + mono 3.4
author cin
date Fri, 22 Aug 2014 17:34:46 +0400
parents 79a04c6442bf
children f757da6161a1
files Source/Data/Linq/Builder/ExpressionBuilder.QueryBuilder.cs Source/Data/Linq/Builder/ExpressionBuilder.SqlBuilder.cs Source/Data/Linq/ReflectionHelper.cs
diffstat 3 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Source/Data/Linq/Builder/ExpressionBuilder.QueryBuilder.cs	Fri Aug 22 13:41:57 2014 +0400
+++ b/Source/Data/Linq/Builder/ExpressionBuilder.QueryBuilder.cs	Fri Aug 22 17:34:46 2014 +0400
@@ -324,7 +324,7 @@
 					{
 						var pi = (MethodCallExpression)expr;
 						var e  = pi;
-						var l  = SqlProvider.ConvertMember(e.Method);
+						var l  = SqlProvider.ConvertMember(ReflectionHelper.ExtractMethodInfo(e));
 
 						if (l != null)
 							return l.Body.Unwrap().Find(PreferServerSide) != null;
--- a/Source/Data/Linq/Builder/ExpressionBuilder.SqlBuilder.cs	Fri Aug 22 13:41:57 2014 +0400
+++ b/Source/Data/Linq/Builder/ExpressionBuilder.SqlBuilder.cs	Fri Aug 22 17:34:46 2014 +0400
@@ -425,7 +425,7 @@
 
 		Expression ConvertMethod(MethodCallExpression pi)
 		{
-			var l = SqlProvider.ConvertMember(pi.Method);
+			var l = SqlProvider.ConvertMember(ReflectionHelper.ExtractMethodInfo(pi));
 			return l == null ? null : ConvertMethod(pi, l);
 		}
 
@@ -914,7 +914,7 @@
 						}
 						else
 						{
-							var l = SqlProvider.ConvertMember(e.Method);
+							var l = SqlProvider.ConvertMember(ReflectionHelper.ExtractMethodInfo(e));
 
 							if (l != null)
 								return l.Body.Unwrap().Find(IsServerSideOnly) != null;
--- a/Source/Data/Linq/ReflectionHelper.cs	Fri Aug 22 13:41:57 2014 +0400
+++ b/Source/Data/Linq/ReflectionHelper.cs	Fri Aug 22 17:34:46 2014 +0400
@@ -41,7 +41,13 @@
 				//if (ex is MemberExpression)
 				//	return ((PropertyInfo)((MemberExpression)ex).Member).GetGetMethod();
 
-				return ((MethodCallExpression)ex).Method;
+				/// HACK
+				var mce = (MethodCallExpression)ex;
+				var mi = mce.Method;
+				if (mi.IsVirtual && mi.DeclaringType != mce.Object.Type)
+					mi = mce.Object.Type.GetMethod(mi.Name, mi.GetParameters().Select(p => p.ParameterType).ToArray());
+
+				return mi;
 			}
 		}
 
@@ -54,10 +60,18 @@
 
 			return
 				ex is MemberExpression     ? ((MemberExpression)    ex).Member :
-				ex is MethodCallExpression ? ((MethodCallExpression)ex).Method :
+				ex is MethodCallExpression ? ExtractMethodInfo((MethodCallExpression)ex) :
 				                 (MemberInfo)((NewExpression)       ex).Constructor;
 		}
 
+		public static MethodInfo ExtractMethodInfo(MethodCallExpression mce) {
+			var mi = mce.Method;
+			if (mi.IsVirtual && mi.DeclaringType != mce.Object.Type)
+				mi = mce.Object.Type.GetMethod(mi.Name, mi.GetParameters().Select(p => p.ParameterType).ToArray());
+
+			return mi;
+		}
+
 		public class Binary : Expressor<BinaryExpression>
 		{
 			public static MethodInfo Conversion = PropertyExpressor(e => e.Conversion);