Parcourir la source

2008-07-19 Jb Evain <[email protected]>

	* Expression.cs (Call, Field, Property): disallow instance arguments
	on static members. See ms connect #339351.


svn path=/trunk/mcs/; revision=108306
Jb Evain il y a 17 ans
Parent
commit
82ca793bbd

+ 5 - 0
mcs/class/System.Core/System.Linq.Expressions/ChangeLog

@@ -1,3 +1,8 @@
+2008-07-19  Jb Evain  <[email protected]>
+
+	* Expression.cs (Call, Field, Property): disallow instance arguments
+	on static members. See ms connect #339351.
+
 2008-07-18  Jb Evain  <[email protected]>
 
 	* Expression.cs, BinaryExpression.cs: fix retrieval of true and false

+ 8 - 3
mcs/class/System.Core/System.Linq.Expressions/Expression.cs

@@ -1018,6 +1018,8 @@ namespace System.Linq.Expressions {
 				throw new ArgumentNullException ("method");
 			if (instance == null && !method.IsStatic)
 				throw new ArgumentNullException ("instance");
+			if (method.IsStatic && instance != null)
+				throw new ArgumentException ("instance");
 			if (!method.IsStatic && !instance.Type.IsAssignableTo (method.DeclaringType))
 				throw new ArgumentException ("Type is not assignable to the declaring type of the method");
 
@@ -1325,7 +1327,8 @@ namespace System.Linq.Expressions {
 					throw new ArgumentNullException ("expression");
 				if (!expression.Type.IsAssignableTo (field.DeclaringType))
 					throw new ArgumentException ("field");
-			}
+			} else if (expression != null)
+				throw new ArgumentException ("expression");
 
 			return new MemberExpression (expression, field, field.FieldType);
 		}
@@ -2060,7 +2063,8 @@ namespace System.Linq.Expressions {
 					throw new ArgumentNullException ("expression");
 				if (!expression.Type.IsAssignableTo (propertyAccessor.DeclaringType))
 					throw new ArgumentException ("expression");
-			}
+			} else if (expression != null)
+				throw new ArgumentException ("expression");
 
 			var prop = GetAssociatedProperty (propertyAccessor);
 			if (prop == null)
@@ -2095,7 +2099,8 @@ namespace System.Linq.Expressions {
 					throw new ArgumentNullException ("expression");
 				if (!expression.Type.IsAssignableTo (property.DeclaringType))
 					throw new ArgumentException ("expression");
-			}
+			} else if (expression != null)
+				throw new ArgumentException ("expression");
 
 			return new MemberExpression (expression, property, property.PropertyType);
 		}