Author: miguel
Date: 2008-01-17 19:24:01 -0500 (Thu, 17 Jan 2008)
New Revision: 93222

Added:
   
trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Lambda.cs
Modified:
   trunk/mcs/class/System.Core/System.Core_test.dll.sources
   trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
   trunk/mcs/class/System.Core/System.Linq.Expressions/ConstantExpression.cs
   trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
   trunk/mcs/class/System.Core/System.Linq.Expressions/Expression_T.cs
   trunk/mcs/class/System.Core/System.Linq.Expressions/LambdaExpression.cs
   
trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Constant.cs
Log:
2008-01-17  Miguel de Icaza  <[EMAIL PROTECTED]>

        Beginning of code generation framework for Linq.Expressions.
        Some code was borrowed by from the C# compiler
        
        * Expression_T.cs: Fill in the blanks.
        
        * LambdaExpression.cs: Validation of parameters mostly, a tiny bit
        of codegen.

        * ConstantExpression.cs: Mostly done, need to write tests for
        non-fundamental types and other ValueType initializations. 




Modified: trunk/mcs/class/System.Core/System.Core_test.dll.sources
===================================================================
--- trunk/mcs/class/System.Core/System.Core_test.dll.sources    2008-01-18 
00:13:21 UTC (rev 93221)
+++ trunk/mcs/class/System.Core/System.Core_test.dll.sources    2008-01-18 
00:24:01 UTC (rev 93222)
@@ -14,6 +14,7 @@
 System.Linq.Expressions/ExpressionTest_Constant.cs
 System.Linq.Expressions/ExpressionTest_Divide.cs
 System.Linq.Expressions/ExpressionTest_Quote.cs
+System.Linq.Expressions/ExpressionTest_Lambda.cs
 System.Linq.Expressions/ExpressionTest_LeftShift.cs
 System.Linq.Expressions/ExpressionTest_MakeBinary.cs
 System.Linq.Expressions/ExpressionTest_Modulo.cs

Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog       
2008-01-18 00:13:21 UTC (rev 93221)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ChangeLog       
2008-01-18 00:24:01 UTC (rev 93222)
@@ -1,3 +1,16 @@
+2008-01-17  Miguel de Icaza  <[EMAIL PROTECTED]>
+
+       Beginning of code generation framework for Linq.Expressions.
+       Some code was borrowed by from the C# compiler
+       
+       * Expression_T.cs: Fill in the blanks.
+       
+       * LambdaExpression.cs: Validation of parameters mostly, a tiny bit
+       of codegen.
+
+       * ConstantExpression.cs: Mostly done, need to write tests for
+       non-fundamental types and other ValueType initializations. 
+
 2008-01-17  Jb Evain  <[EMAIL PROTECTED]>
 
        * Expression.cs: implement MakeMemberAccess.

Modified: 
trunk/mcs/class/System.Core/System.Linq.Expressions/ConstantExpression.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/ConstantExpression.cs   
2008-01-18 00:13:21 UTC (rev 93221)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/ConstantExpression.cs   
2008-01-18 00:24:01 UTC (rev 93222)
@@ -3,9 +3,14 @@
 //
 // Author:
 //   Jb Evain ([EMAIL PROTECTED])
+//   Miguel de Icaza ([EMAIL PROTECTED])
 //
-// (C) 2008 Novell, Inc. (http://www.novell.com)
+// Some code is based on the Mono C# compiler:
+//   Marek Safar ([EMAIL PROTECTED])
+//   Martin Baulig ([EMAIL PROTECTED])
 //
+// (C) 2001-2008 Novell, Inc. (http://www.novell.com)
+//
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // "Software"), to deal in the Software without restriction, including
@@ -27,11 +32,12 @@
 //
 
 using System;
+using System.Reflection;
+using System.Reflection.Emit;
 
 namespace System.Linq.Expressions {
 
        public sealed class ConstantExpression : Expression {
-
                object value;
 
                public object Value {
@@ -43,5 +49,96 @@
                {
                        this.value = value;
                }
+
+               internal override void Emit (EmitContext ec)
+               {
+                       ILGenerator ig = ec.ig;
+                       
+                       switch (Type.GetTypeCode (Type)){
+                       case TypeCode.Byte:
+                               ig.Emit (OpCodes.Ldc_I4, (int) ((byte)value));
+                               return;
+                                             
+                       case TypeCode.SByte:
+                               ig.Emit (OpCodes.Ldc_I4, (int) ((sbyte)value));
+                               return;
+                                       
+                       case TypeCode.Int16:
+                               ig.Emit (OpCodes.Ldc_I4, (int) ((short)value));
+                               return;
+                               
+                       case TypeCode.UInt16:
+                               ig.Emit (OpCodes.Ldc_I4, (int) ((ushort)value));
+                               return;
+                               
+                       case TypeCode.Int32:
+                               ig.Emit (OpCodes.Ldc_I4, (int) value);
+                               return;
+                               
+                       case TypeCode.UInt32:
+                               ig.Emit (OpCodes.Ldc_I4, unchecked ((int) 
((uint)Value)));
+                               return;
+                               
+                       case TypeCode.Int64:
+                               ig.Emit (OpCodes.Ldc_I8, (long) value);
+                               return;
+                                       
+                       case TypeCode.UInt64:
+                               ig.Emit (OpCodes.Ldc_I8, unchecked ((long) 
((ulong)value)));
+                               return;
+
+                       case TypeCode.Boolean:
+                               if ((bool) Value)
+                                       ig.Emit (OpCodes.Ldc_I4_1);
+                               else
+                                       ec.ig.Emit (OpCodes.Ldc_I4_0);
+                               return;
+                               
+                       case TypeCode.Char:
+                               ig.Emit (OpCodes.Ldc_I4, (int) ((char) value));
+                               return;
+                               
+                       case TypeCode.Single:
+                               ig.Emit (OpCodes.Ldc_R4, (float) value);
+                               return;
+                               
+                       case TypeCode.Double:
+                               ig.Emit (OpCodes.Ldc_R8, (double) value);
+                               return;
+                               
+                       case TypeCode.Decimal: {
+                               Decimal v = (decimal) value;
+                               int [] words = Decimal.GetBits (v);
+                               int power = (words [3] >> 16) & 0xff;
+                               Type ti = typeof (int);
+                               
+                               if (power == 0 && v <= int.MaxValue && v >= 
int.MinValue) {
+                                       ig.Emit (OpCodes.Ldc_I4, (int) v);
+                                       
+                                       ig.Emit (OpCodes.Newobj, typeof 
(Decimal).GetConstructor (new Type [1] { ti }));
+                                       return;
+                               }
+                               ig.Emit (OpCodes.Ldc_I4, words [0]);
+                               ig.Emit (OpCodes.Ldc_I4, words [1]);
+                               ig.Emit (OpCodes.Ldc_I4, words [2]);
+                               // sign
+                               ig.Emit (OpCodes.Ldc_I4, words [3] >> 31);
+
+                               // power
+                               ig.Emit (OpCodes.Ldc_I4, power);
+
+                               ig.Emit (OpCodes.Newobj, typeof 
(Decimal).GetConstructor (new Type [5] { ti, ti, ti, typeof(bool), typeof(byte) 
}));
+                               return;
+                        }
+
+                       case TypeCode.String:
+                               ig.Emit (OpCodes.Ldstr, (string) value);
+                               return;
+                       }
+
+                       // FIXME: complete the implementation
+                       
+                       throw new NotImplementedException (String.Format ("No 
support for constants of type {0} yet", Type));
+               }
        }
 }

Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs   
2008-01-18 00:13:21 UTC (rev 93221)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/Expression.cs   
2008-01-18 00:24:01 UTC (rev 93222)
@@ -874,10 +874,12 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public static Expression<TDelegate> Lambda<TDelegate> 
(Expression body, params ParameterExpression [] parameters)
                {
-                       throw new NotImplementedException ();
+                       if (body == null)
+                               throw new ArgumentNullException ("body");
+
+                       return new Expression<TDelegate> (body, parameters);
                }
 
                [MonoTODO]
@@ -892,16 +894,25 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public static LambdaExpression Lambda (Type delegateType, 
Expression body, params ParameterExpression [] parameters)
                {
-                       throw new NotImplementedException ();
+                       if (delegateType == null)
+                               throw new ArgumentNullException 
("delegateType");
+                       if (body == null)
+                               throw new ArgumentNullException ("body");
+
+                       return new LambdaExpression (delegateType, body, new 
ReadOnlyCollection<ParameterExpression> (parameters));
                }
 
                [MonoTODO]
                public static LambdaExpression Lambda (Type delegateType, 
Expression body, IEnumerable<ParameterExpression> parameters)
                {
-                       throw new NotImplementedException ();
+                       if (delegateType == null)
+                               throw new ArgumentNullException 
("delegateType");
+                       if (body == null)
+                               throw new ArgumentNullException ("body");
+
+                       return new LambdaExpression (delegateType, body, 
parameters);
                }
 
                public static MemberListBinding ListBind (MemberInfo member, 
params ElementInit [] initializers)
@@ -1222,5 +1233,14 @@
                {
                        return type.IsGenericType && 
type.GetGenericTypeDefinition () == typeof (Nullable<>);
                }
+
+               //
+               // This method must be overwritten by derived classes to
+               // compile the expression
+               //
+               internal virtual void Emit (EmitContext ec)
+               {
+                       throw new NotImplementedException (String.Format ("{0} 
does not implement Emit yet", GetType ()));
+               }
        }
 }

Modified: trunk/mcs/class/System.Core/System.Linq.Expressions/Expression_T.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/Expression_T.cs 
2008-01-18 00:13:21 UTC (rev 93221)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/Expression_T.cs 
2008-01-18 00:24:01 UTC (rev 93222)
@@ -27,15 +27,26 @@
 //
 
 using System;
+using System.Collections.ObjectModel;
+using System.Collections.Generic;
 
 namespace System.Linq.Expressions {
 
        public sealed class Expression<TDelegate> : LambdaExpression {
 
-               [MonoTODO]
+               internal Expression (Expression body, 
IEnumerable<ParameterExpression> parameters)
+                       : base (typeof (TDelegate), body, new 
ReadOnlyCollection<ParameterExpression>(new 
List<ParameterExpression>(parameters)))
+               {
+               }
+               
+               internal Expression (Expression body, ParameterExpression [] 
parameters)
+                       : base (typeof (TDelegate), body, new 
ReadOnlyCollection<ParameterExpression>(parameters))
+               {
+               }
+               
                public new TDelegate Compile ()
                {
-                       throw new NotImplementedException ();
+                       return (TDelegate) (object) ((LambdaExpression) 
this).Compile ();
                }
        }
 }

Modified: 
trunk/mcs/class/System.Core/System.Linq.Expressions/LambdaExpression.cs
===================================================================
--- trunk/mcs/class/System.Core/System.Linq.Expressions/LambdaExpression.cs     
2008-01-18 00:13:21 UTC (rev 93221)
+++ trunk/mcs/class/System.Core/System.Linq.Expressions/LambdaExpression.cs     
2008-01-18 00:24:01 UTC (rev 93222)
@@ -3,6 +3,7 @@
 //
 // Author:
 //   Jb Evain ([EMAIL PROTECTED])
+//   Miguel de Icaza ([EMAIL PROTECTED])
 //
 // (C) 2008 Novell, Inc. (http://www.novell.com)
 //
@@ -28,14 +29,112 @@
 
 using System;
 using System.Collections.ObjectModel;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Reflection.Emit;
 
 namespace System.Linq.Expressions {
 
+       internal class EmitContext {
+               internal LambdaExpression Owner;
+               internal Type [] ParamTypes;
+               internal DynamicMethod Method;
+               internal ILGenerator ig;
+               
+               static object mlock = new object ();
+               static int method_count;
+               static string GenName ()
+               {
+                       lock (mlock){
+                               return "<LINQ-" + method_count++ + ">";
+                       }
+               }
+               
+               public EmitContext (LambdaExpression owner)
+               {
+                       Owner = owner;
+
+                       ParamTypes = new Type [Owner.parameters.Count];
+                       for (int i = 0; i < Owner.parameters.Count; i++)
+                               ParamTypes [i] = Owner.parameters [i].Type;
+
+                       //
+                       // We probably want to use the 3.5 new API calls to 
associate
+                       // the method with the "sandboxed" Assembly, instead am 
currently
+                       // dumping these types in this class
+                       //
+                       Type owner_of_code = typeof (EmitContext);
+                       
+                       Method = new DynamicMethod (GenName (), Owner.Type, 
ParamTypes, owner_of_code);
+                       ig = Method.GetILGenerator ();
+               }
+
+               internal Delegate CreateDelegate ()
+               {
+                       return Method.CreateDelegate (Owner.delegate_type);     
                
+               }
+       }
+       
        public class LambdaExpression : Expression {
 
+               //
+               // LambdaExpression parameters
+               //
                Expression body;
-               ReadOnlyCollection<ParameterExpression> parameters;
+               internal ReadOnlyCollection<ParameterExpression> parameters;
+               internal Type delegate_type;
 
+               // This is set during compilation
+               Delegate lambda_delegate;
+
+               static bool CanAssign (Type target, Type source)
+               {
+                       // This catches object and value type mixage, type 
compatibility is handled later
+                       if (target.IsValueType ^ source.IsValueType)
+                               return false;
+                       
+                       return target.IsAssignableFrom (source);
+               }
+
+               internal LambdaExpression (Type delegateType, Expression body, 
IEnumerable<ParameterExpression> parameters)
+                       : this (delegateType, body, new 
ReadOnlyCollection<ParameterExpression> (new List<ParameterExpression> 
(parameters)))
+                       {
+                       }
+                               
+               internal LambdaExpression (Type delegateType, Expression body, 
ReadOnlyCollection<ParameterExpression> parameters)
+                       : base (ExpressionType.Lambda, body.Type)
+               {
+                       if (!delegateType.IsSubclassOf (typeof 
(System.Delegate))){
+                               throw new ArgumentException ("delegateType");
+                       }
+                       
+                       MethodInfo [] invokes = delegateType.GetMethods 
(BindingFlags.Instance | BindingFlags.Public);
+                       MethodInfo invoke = null;
+                       foreach (MethodInfo m in invokes)
+                               if (m.Name == "Invoke"){
+                                       invoke = m;
+                                       break;
+                               }
+                       if (invoke == null)
+                               throw new ArgumentException ("delegate must 
contain an Invoke method", "delegateType");
+
+                       ParameterInfo [] invoke_parameters = 
invoke.GetParameters ();
+                       if (invoke_parameters.Length != parameters.Count)
+                               throw new ArgumentException ("Different number 
of arguments in delegate {0}", "delegateType");
+
+                       for (int i = 0; i < invoke_parameters.Length; i++){
+                               if (!CanAssign (parameters [i].Type, 
invoke_parameters [i].ParameterType))
+                                       throw new ArgumentException 
(String.Format ("Can not assign a {0} to a {1}", invoke_parameters 
[i].ParameterType, parameters [i].Type));
+                       }
+
+                       if (!CanAssign (invoke.ReturnType, body.Type))
+                               throw new ArgumentException (String.Format 
("body type {0} can not be assigned to {1}", body.Type, invoke.ReturnType));
+                       
+                       this.body = body;
+                       this.parameters = parameters;
+                       delegate_type = delegateType;
+               }
+               
                public Expression Body {
                        get { return body; }
                }
@@ -44,10 +143,17 @@
                        get { return parameters; }
                }
 
-               [MonoTODO]
                public Delegate Compile ()
                {
-                       throw new NotImplementedException ();
+                       if (lambda_delegate == null){
+                               EmitContext ec = new EmitContext (this);
+                               
+                               body.Emit (ec);
+
+                               ec.ig.Emit (OpCodes.Ret);
+                               lambda_delegate = ec.CreateDelegate ();
+                       }
+                       return lambda_delegate;
                }
        }
 }

Modified: 
trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Constant.cs
===================================================================
--- 
trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Constant.cs
 2008-01-18 00:13:21 UTC (rev 93221)
+++ 
trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Constant.cs
 2008-01-18 00:24:01 UTC (rev 93222)
@@ -139,6 +139,50 @@
                        // type mismatch: int value, type == double 
                        Expression.Constant (0, typeof (double));
                }
+
+               static T Check<T> (T val)
+               {
+                       Expression<Func<T>> l = Expression.Lambda<Func<T>> 
(Expression.Constant (val), new ParameterExpression [0]);
+                       Func<T> fi = l.Compile ();
+                       return fi ();
+               }
                
+               [Test]
+               public void ConstantCodeGen ()
+               {
+                       Assert.AreEqual (Check<int> (0), 0, "int");
+                       Assert.AreEqual (Check<int> (128), 128, "int2");
+                       Assert.AreEqual (Check<int> (-128), -128, "int3");
+                       Assert.AreEqual (Check<int> (Int32.MinValue), 
Int32.MinValue, "int4");
+                       Assert.AreEqual (Check<int> (Int32.MaxValue), 
Int32.MaxValue, "int5");
+                       Assert.AreEqual (Check<uint> (128), 128, "uint");
+                       Assert.AreEqual (Check<uint> (0), 0, "uint2");
+                       Assert.AreEqual (Check<uint> (UInt32.MinValue), 
UInt32.MinValue, "uint3");
+                       Assert.AreEqual (Check<uint> (UInt32.MaxValue), 
UInt32.MaxValue, "uint4");
+                       Assert.AreEqual (Check<byte> (10), 10, "byte");
+                       Assert.AreEqual (Check<byte> (Byte.MinValue), 
Byte.MinValue, "byte2");
+                       Assert.AreEqual (Check<byte> (Byte.MaxValue), 
Byte.MaxValue, "byte3");
+                       Assert.AreEqual (Check<short> (128), 128, "short");
+                       Assert.AreEqual (Check<short> (-128), -128, "short");
+                       Assert.AreEqual (Check<short> (Int16.MinValue), 
Int16.MinValue, "short2");
+                       Assert.AreEqual (Check<short> (Int16.MaxValue), 
Int16.MaxValue, "short3");
+                       Assert.AreEqual (Check<ushort> (128), 128, "ushort");
+                       Assert.AreEqual (Check<ushort> (UInt16.MinValue), 
UInt16.MinValue, "short2");
+                       Assert.AreEqual (Check<ushort> (UInt16.MaxValue), 
UInt16.MaxValue, "short3");
+                       Assert.AreEqual (Check<bool> (true), true, "bool1");
+                       Assert.AreEqual (Check<bool> (false), false, "bool2");
+                       Assert.AreEqual (Check<long> (Int64.MaxValue), 
Int64.MaxValue, "long");
+                       Assert.AreEqual (Check<long> (Int64.MinValue), 
Int64.MinValue, "long2");
+                       Assert.AreEqual (Check<ulong> (UInt64.MaxValue), 
UInt64.MaxValue, "ulong");
+                       Assert.AreEqual (Check<ulong> (UInt64.MinValue), 
UInt64.MinValue, "ulong2");
+                       Assert.AreEqual (Check<ushort> (200), 200, "ushort");
+                       Assert.AreEqual (Check<float> (2.0f), 2.0f, "float");
+                       Assert.AreEqual (Check<double> (2.312), 2.312, 
"double");
+                       Assert.AreEqual (Check<string> ("dingus"), "dingus", 
"string");
+                       Assert.AreEqual (Check<decimal> (1.3m), 1.3m, "");
+
+                       // this forces the other code path for decimal.
+                       Assert.AreEqual (Check<decimal> (3147483647m), 
3147483647m, "decimal");
+               }
        }
 }

Added: 
trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Lambda.cs
===================================================================
--- 
trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Lambda.cs
   2008-01-18 00:13:21 UTC (rev 93221)
+++ 
trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Lambda.cs
   2008-01-18 00:24:01 UTC (rev 93222)
@@ -0,0 +1,118 @@
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+//
+// Authors:
+//   Miguel de Icaza ([EMAIL PROTECTED])
+
+using System;
+using System.Reflection;
+using System.Linq;
+using System.Linq.Expressions;
+using NUnit.Framework;
+
+namespace MonoTests.System.Linq.Expressions
+{
+       [TestFixture]
+       public class ExpressionTest_Lambda
+       {
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void NonDelegateTypeInCtor ()
+               {
+                       // The first parameter must be a delegate type
+                       Expression.Lambda (typeof(string), Expression.Constant 
(1), new ParameterExpression [0]);
+               }
+
+               delegate object delegate_object_emtpy ();
+               delegate object delegate_object_int (int a);
+               delegate object delegate_object_string (string s);
+               delegate object delegate_object_object (object s);
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void InvalidConversion ()
+               {
+                       // float to object, invalid
+                       Expression.Lambda (typeof (delegate_object_emtpy), 
Expression.Constant (1.0), new ParameterExpression [0]);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void InvalidConversion2 ()
+               {
+                       // float to object, invalid
+                       Expression.Lambda (typeof (delegate_object_emtpy), 
Expression.Constant (1), new ParameterExpression [0]);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void InvalidArgCount ()
+               {
+                       // missing a parameter
+                       Expression.Lambda (typeof (delegate_object_int), 
Expression.Constant ("foo"), new ParameterExpression [0]);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void InvalidArgCount2 ()
+               {
+                       // extra parameter
+                       ParameterExpression p = Expression.Parameter (typeof 
(int), "AAA");
+                       Expression.Lambda (typeof (delegate_object_emtpy), 
Expression.Constant ("foo"), new ParameterExpression [1] {p});
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void InvalidArgType ()
+               {
+                       // invalid argument type
+                       
+                       ParameterExpression p = Expression.Parameter (typeof 
(string), "AAA");
+                       Expression.Lambda (typeof (delegate_object_int), 
Expression.Constant ("foo"), new ParameterExpression [1] {p});
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void InvalidArgType2 ()
+               {
+                       // invalid argument type
+                       
+                       ParameterExpression p = Expression.Parameter (typeof 
(string), "AAA");
+                       Expression.Lambda (typeof (delegate_object_object), 
Expression.Constant ("foo"), new ParameterExpression [1] {p});
+               }
+               
+               [Test]
+               public void Assignability ()
+               {
+                       // allowed: string to object
+                       Expression.Lambda (typeof (delegate_object_emtpy), 
Expression.Constant ("string"), new ParameterExpression [0]);
+
+                       // allowed delegate has string, delegate has base class 
(object)
+                       ParameterExpression p = Expression.Parameter (typeof 
(object), "ParObject");
+                       Expression.Lambda (typeof (delegate_object_string), 
Expression.Constant (""), new ParameterExpression [1] {p});
+               }
+
+               [Test]
+               public void Compile ()
+               {
+                       Expression<Func<int>> l = Expression.Lambda<Func<int>> 
(Expression.Constant (1), new ParameterExpression [0]);
+                       Func<int> fi = l.Compile ();
+                       fi ();
+               }
+       }
+}


Property changes on: 
trunk/mcs/class/System.Core/Test/System.Linq.Expressions/ExpressionTest_Lambda.cs
___________________________________________________________________
Name: svn:eol-style
   + native

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to