Browse Source

2008-01-09 Jb Evain <[email protected]>

	* Expression.cs: implement GetActionType.


svn path=/trunk/mcs/; revision=92533
Jb Evain 18 years ago
parent
commit
c86b0397df

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

@@ -1,3 +1,7 @@
+2008-01-09  Jb Evain  <[email protected]>
+
+	* Expression.cs: implement GetActionType.
+
 2008-01-09  Jb Evain  <[email protected]>
 
 	* Expression.cs: fix GetFuncType to return the correct type

+ 27 - 0
mcs/class/System.Core/System.Linq.Expressions/Expression.cs

@@ -721,6 +721,33 @@ namespace System.Linq.Expressions
 		}
 		#endregion
 
+		public static Type GetActionType (params Type [] typeArgs)
+		{
+			if (typeArgs == null)
+				throw new ArgumentNullException ("typeArgs");
+
+			if (typeArgs.Length < 1 || typeArgs.Length > 4)
+				throw new ArgumentException ("No Action type of this arity");
+
+			Type action = null;
+			switch (typeArgs.Length) {
+			case 1:
+				action = typeof (Action<>);
+				break;
+			case 2:
+				action = typeof (Action<,>);
+				break;
+			case 3:
+				action = typeof (Action<,,>);
+				break;
+			case 4:
+				action = typeof (Action<,,,>);
+				break;
+			}
+
+			return action.MakeGenericType (typeArgs);
+		}
+
 		public static Type GetFuncType (params Type [] typeArgs)
 		{
 			if (typeArgs == null)