5 // Jb Evain (jbevain@novell.com)
6 // Miguel de Icaza (miguel@novell.com)
8 // (C) 2008 Novell, Inc. (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections.Generic;
32 using System.Collections.ObjectModel;
33 using System.Reflection;
35 namespace System.Linq.Expressions {
37 public abstract class Expression {
39 ExpressionType node_type;
42 public ExpressionType NodeType {
43 get { return node_type; }
50 // TODO: remove when all Expression subtypes
51 // have their constructor implemented
52 protected Expression ()
56 protected Expression (ExpressionType node_type, Type type)
58 this.node_type = node_type;
62 public override string ToString ()
64 return ExpressionPrinter.ToString (this);
67 #region Binary Expressions
69 static void BinaryCoreCheck (Expression left, Expression right)
72 throw new ArgumentNullException ("left");
74 throw new ArgumentNullException ("right");
76 if (left.Type != right.Type)
77 throw new InvalidOperationException ("Both expressions must have the same type");
80 static BinaryExpression MakeSimpleBinary (ExpressionType et, Expression left, Expression right, MethodInfo method)
82 return new BinaryExpression (et, left.Type, left, right, method);
85 static BinaryExpression MakeSimpleBinary (ExpressionType et, Type result, Expression left, Expression right, MethodInfo method)
87 return new BinaryExpression (et, result, left, right, method);
90 static BinaryExpression MakeBoolBinary (ExpressionType et, Expression left, Expression right, bool liftToNull, MethodInfo method)
92 return new BinaryExpression (et, typeof (bool), left, right, method);
98 public static BinaryExpression Add (Expression left, Expression right)
100 return Add (left, right, null);
103 public static BinaryExpression Add (Expression left, Expression right, MethodInfo method)
105 BinaryCoreCheck (left, right);
107 return MakeSimpleBinary (ExpressionType.Add, left, right, method);
110 public static BinaryExpression AddChecked (Expression left, Expression right)
112 return AddChecked (left, right, null);
115 public static BinaryExpression AddChecked (Expression left, Expression right, MethodInfo method)
117 return MakeSimpleBinary (ExpressionType.AddChecked, left, right, method);
120 public static BinaryExpression Subtract (Expression left, Expression right)
122 return Subtract (left, right, null);
125 public static BinaryExpression Subtract (Expression left, Expression right, MethodInfo method)
127 BinaryCoreCheck (left, right);
128 return MakeSimpleBinary (ExpressionType.Subtract, left, right, method);
131 public static BinaryExpression SubtractChecked (Expression left, Expression right)
133 return SubtractChecked (left, right, null);
136 public static BinaryExpression SubtractChecked (Expression left, Expression right, MethodInfo method)
138 BinaryCoreCheck (left, right);
139 return MakeSimpleBinary (ExpressionType.SubtractChecked, left, right, method);
142 public static BinaryExpression Modulo (Expression left, Expression right)
144 return Modulo (left, right, null);
147 public static BinaryExpression Modulo (Expression left, Expression right, MethodInfo method)
149 BinaryCoreCheck (left, right);
151 return MakeSimpleBinary (ExpressionType.Modulo, left, right, method);
154 public static BinaryExpression Multiply (Expression left, Expression right)
156 return Multiply (left, right);
159 public static BinaryExpression Multiply (Expression left, Expression right, MethodInfo method)
161 BinaryCoreCheck (left, right);
163 return MakeSimpleBinary (ExpressionType.Multiply, left, right, method);
166 public static BinaryExpression MultiplyChecked (Expression left, Expression right)
168 return MultiplyChecked (left, right, null);
171 public static BinaryExpression MultiplyChecked (Expression left, Expression right, MethodInfo method)
173 BinaryCoreCheck (left, right);
175 return MakeSimpleBinary (ExpressionType.MultiplyChecked, left, right, method);
178 public static BinaryExpression Divide (Expression left, Expression right)
180 return Divide (left, right, null);
183 public static BinaryExpression Divide (Expression left, Expression right, MethodInfo method)
185 BinaryCoreCheck (left, right);
187 return MakeSimpleBinary (ExpressionType.Divide, left, right, method);
190 public static BinaryExpression Power (Expression left, Expression right)
192 return Power (left, right, null);
195 public static BinaryExpression Power (Expression left, Expression right, MethodInfo method)
197 BinaryCoreCheck (left, right);
199 if (left.Type != typeof (double))
200 throw new InvalidOperationException ("Power only supports double arguments");
202 return MakeSimpleBinary (ExpressionType.Power, left, right, method);
208 static bool IsInt (Type t)
211 t == typeof (int) || t == typeof (uint) ||
212 t == typeof (short) || t == typeof (ushort) ||
213 t == typeof (long) || t == typeof (ulong);
216 public static BinaryExpression And (Expression left, Expression right)
218 return And (left, right, null);
221 public static BinaryExpression And (Expression left, Expression right, MethodInfo method)
223 BinaryCoreCheck (left, right);
225 if (left.Type == typeof (bool) || IsInt (left.Type))
226 return MakeSimpleBinary (ExpressionType.And, left, right, method);
228 throw new InvalidOperationException ("Only integral or bool types allowed");
231 public static BinaryExpression Or (Expression left, Expression right)
233 return Or (left, right, null);
236 public static BinaryExpression Or (Expression left, Expression right, MethodInfo method)
238 BinaryCoreCheck (left, right);
240 if (left.Type == typeof (bool) || IsInt (left.Type))
241 return MakeSimpleBinary (ExpressionType.Or, left, right, method);
243 throw new InvalidOperationException ("Only integral or bool types allowed");
246 public static BinaryExpression ExclusiveOr (Expression left, Expression right)
248 return ExclusiveOr (left, right);
251 public static BinaryExpression ExclusiveOr (Expression left, Expression right, MethodInfo method)
253 BinaryCoreCheck (left, right);
255 if (left.Type == typeof (bool) || IsInt (left.Type))
256 return MakeSimpleBinary (ExpressionType.ExclusiveOr, left, right, method);
258 throw new InvalidOperationException ("Only integral or bool types allowed");
261 public static BinaryExpression LeftShift (Expression left, Expression right)
263 return LeftShift (left, right, null);
266 public static BinaryExpression LeftShift (Expression left, Expression right, MethodInfo method)
268 BinaryCoreCheck (left, right);
270 if (left.Type == typeof (int))
271 return MakeSimpleBinary (ExpressionType.LeftShift, left, right, method);
273 throw new InvalidOperationException ("Only int32 is allowed for shifts");
276 public static BinaryExpression RightShift (Expression left, Expression right)
278 return RightShift (left, right);
281 public static BinaryExpression RightShift (Expression left, Expression right, MethodInfo method)
283 BinaryCoreCheck (left, right);
284 if (left.Type == typeof (int))
285 return MakeSimpleBinary (ExpressionType.RightShift, left, right, method);
287 throw new InvalidOperationException ("Only int32 is allowed for shifts");
293 public static BinaryExpression AndAlso (Expression left, Expression right)
295 return AndAlso (left, right, null);
299 public static BinaryExpression AndAlso (Expression left, Expression right, MethodInfo method)
301 // This does not work with int, int pairs; Figure out when its valid
303 throw new NotImplementedException ();
307 public static BinaryExpression OrElse (Expression left, Expression right)
309 throw new NotImplementedException ();
313 public static BinaryExpression OrElse (Expression left, Expression right, MethodInfo method)
315 throw new NotImplementedException ();
321 public static BinaryExpression Equal (Expression left, Expression right)
323 return Equal (left, right, false, null);
326 public static BinaryExpression Equal (Expression left, Expression right, bool liftToNull, MethodInfo method)
328 BinaryCoreCheck (left, right);
330 return MakeBoolBinary (ExpressionType.Equal, left, right, liftToNull, method);
333 public static BinaryExpression NotEqual (Expression left, Expression right)
335 return NotEqual (left, right, false, null);
339 public static BinaryExpression NotEqual (Expression left, Expression right, bool liftToNull, MethodInfo method)
341 BinaryCoreCheck (left, right);
343 return MakeBoolBinary (ExpressionType.NotEqual, left, right, liftToNull, method);
346 public static BinaryExpression GreaterThan (Expression left, Expression right)
348 return GreaterThan (left, right, false, null);
351 public static BinaryExpression GreaterThan (Expression left, Expression right, bool liftToNull, MethodInfo method)
353 BinaryCoreCheck (left, right);
355 return MakeBoolBinary (ExpressionType.GreaterThan, left, right, liftToNull, method);
358 public static BinaryExpression GreaterThanOrEqual (Expression left, Expression right)
360 return GreaterThanOrEqual (left, right, false, null);
364 public static BinaryExpression GreaterThanOrEqual (Expression left, Expression right, bool liftToNull, MethodInfo method)
366 BinaryCoreCheck (left, right);
368 return MakeBoolBinary (ExpressionType.GreaterThanOrEqual, left, right, liftToNull, method);
371 public static BinaryExpression LessThan (Expression left, Expression right)
373 return LessThan (left, right, false, null);
376 public static BinaryExpression LessThan (Expression left, Expression right, bool liftToNull, MethodInfo method)
378 return MakeBoolBinary (ExpressionType.LessThan, left, right, liftToNull, method);
381 public static BinaryExpression LessThanOrEqual (Expression left, Expression right)
383 return LessThanOrEqual (left, right, false, null);
386 public static BinaryExpression LessThanOrEqual (Expression left, Expression right, bool liftToNull, MethodInfo method)
388 BinaryCoreCheck (left, right);
390 return MakeBoolBinary (ExpressionType.LessThanOrEqual, left, right, liftToNull, method);
397 public static BinaryExpression ArrayIndex (Expression left, Expression index)
399 throw new NotImplementedException ();
402 public static BinaryExpression Coalesce (Expression left, Expression right)
404 return Coalesce (left, right, null);
408 public static BinaryExpression Coalesce (Expression left, Expression right, LambdaExpression conversion)
410 BinaryCoreCheck (left, right);
412 throw new NotImplementedException ();
416 // MakeBinary constructors
418 public static BinaryExpression MakeBinary (ExpressionType binaryType, Expression left, Expression right)
420 return MakeBinary (binaryType, left, right, false, null);
423 public static BinaryExpression MakeBinary (ExpressionType binaryType, Expression left, Expression right, bool liftToNull, MethodInfo method)
425 return MakeBinary (binaryType, left, right, liftToNull, method, null);
428 public static BinaryExpression MakeBinary (ExpressionType binaryType, Expression left, Expression right, bool liftToNull, MethodInfo method, LambdaExpression conversion)
430 switch (binaryType) {
431 case ExpressionType.Add:
432 return Add (left, right, method);
433 case ExpressionType.AddChecked:
434 return AddChecked (left, right, method);
435 case ExpressionType.AndAlso:
436 return AndAlso (left, right);
437 case ExpressionType.Coalesce:
438 return Coalesce (left, right, conversion);
439 case ExpressionType.Divide:
440 return Divide (left, right, method);
441 case ExpressionType.Equal:
442 return Equal (left, right, liftToNull, method);
443 case ExpressionType.ExclusiveOr:
444 return ExclusiveOr (left, right, method);
445 case ExpressionType.GreaterThan:
446 return GreaterThan (left, right, liftToNull, method);
447 case ExpressionType.GreaterThanOrEqual:
448 return GreaterThanOrEqual (left, right, liftToNull, method);
449 case ExpressionType.LeftShift:
450 return LeftShift (left, right, method);
451 case ExpressionType.LessThan:
452 return LessThan (left, right, liftToNull, method);
453 case ExpressionType.LessThanOrEqual:
454 return LessThanOrEqual (left, right, liftToNull, method);
455 case ExpressionType.Modulo:
456 return Modulo (left, right, method);
457 case ExpressionType.Multiply:
458 return Multiply (left, right, method);
459 case ExpressionType.MultiplyChecked:
460 return MultiplyChecked (left, right, method);
461 case ExpressionType.NotEqual:
462 return NotEqual (left, right, liftToNull, method);
463 case ExpressionType.OrElse:
464 return OrElse (left, right);
465 case ExpressionType.Power:
466 return Power (left, right, method);
467 case ExpressionType.RightShift:
468 return RightShift (left, right, method);
469 case ExpressionType.Subtract:
470 return Subtract (left, right, method);
471 case ExpressionType.SubtractChecked:
472 return SubtractChecked (left, right, method);
473 case ExpressionType.And:
474 return And (left, right, method);
475 case ExpressionType.Or:
476 return Or (left, right, method);
479 throw new ArgumentException ("MakeBinary expect a binary node type");
485 public static MethodCallExpression ArrayIndex (Expression left, params Expression [] indexes)
487 throw new NotImplementedException ();
491 public static MethodCallExpression ArrayIndex (Expression left, IEnumerable<Expression> indexes)
493 throw new NotImplementedException ();
496 public static UnaryExpression ArrayLength (Expression array)
499 throw new ArgumentNullException ("array");
500 if (!array.Type.IsArray)
501 throw new ArgumentException ("The type of the expression must me Array");
502 if (array.Type.GetArrayRank () != 1)
503 throw new ArgumentException ("The array must be a single dimensional array");
505 return new UnaryExpression (ExpressionType.ArrayLength, array, typeof (int));
509 public static MemberAssignment Bind (MemberInfo member, Expression expression)
511 throw new NotImplementedException ();
515 public static MemberAssignment Bind (MethodInfo propertyAccessor, Expression expression)
517 throw new NotImplementedException ();
521 public static MethodCallExpression Call (Expression instance, MethodInfo method)
523 throw new NotImplementedException ();
527 public static MethodCallExpression Call (MethodInfo method, params Expression [] arguments)
529 throw new NotImplementedException ();
533 public static MethodCallExpression Call (Expression instance, MethodInfo method, params Expression [] arguments)
535 throw new NotImplementedException ();
539 public static MethodCallExpression Call (Expression instance, MethodInfo method, IEnumerable<Expression> arguments)
541 throw new NotImplementedException ();
545 public static MethodCallExpression Call (Expression instance, string methodName, Type [] typeArguments, params Expression [] arguments)
547 throw new NotImplementedException ();
551 public static MethodCallExpression Call (Type type, string methodName, Type [] typeArguments, params Expression [] arguments)
553 throw new NotImplementedException ();
557 public static ConditionalExpression Condition (Expression test, Expression ifTrue, Expression ifFalse)
559 throw new NotImplementedException ();
562 public static ConstantExpression Constant (object value)
565 return new ConstantExpression (null, typeof (object));
567 return Constant (value, value.GetType ());
570 public static ConstantExpression Constant (object value, Type type)
573 throw new ArgumentNullException ("type");
576 // value must be compatible with type, no conversions
580 if (type.IsValueType && !IsNullable (type))
581 throw new ArgumentException ();
583 if (!(type.IsValueType && IsNullable (type)) && value.GetType () != type)
584 throw new ArgumentException ();
588 return new ConstantExpression (value, type);
592 public static UnaryExpression Convert (Expression expression, Type type)
594 throw new NotImplementedException ();
598 public static UnaryExpression Convert (Expression expression, Type type, MethodInfo method)
600 throw new NotImplementedException ();
604 public static UnaryExpression ConvertChecked (Expression expression, Type type)
606 throw new NotImplementedException ();
610 public static UnaryExpression ConvertChecked (Expression expression, Type type, MethodInfo method)
612 throw new NotImplementedException ();
616 public static ElementInit ElementInit (MethodInfo addMethod, params Expression [] arguments)
618 throw new NotImplementedException ();
622 public static ElementInit ElementInit (MethodInfo addMethod, IEnumerable<Expression> arguments)
624 throw new NotImplementedException ();
628 public static MemberExpression Field (Expression expression, FieldInfo field)
630 throw new NotImplementedException ();
634 public static MemberExpression Field (Expression expression, string fieldName)
636 throw new NotImplementedException ();
639 public static Type GetActionType (params Type [] typeArgs)
641 if (typeArgs == null)
642 throw new ArgumentNullException ("typeArgs");
644 if (typeArgs.Length > 4)
645 throw new ArgumentException ("No Action type of this arity");
647 if (typeArgs.Length == 0)
648 return typeof (Action);
651 switch (typeArgs.Length) {
653 action = typeof (Action<>);
656 action = typeof (Action<,>);
659 action = typeof (Action<,,>);
662 action = typeof (Action<,,,>);
666 return action.MakeGenericType (typeArgs);
669 public static Type GetFuncType (params Type [] typeArgs)
671 if (typeArgs == null)
672 throw new ArgumentNullException ("typeArgs");
674 if (typeArgs.Length < 1 || typeArgs.Length > 5)
675 throw new ArgumentException ("No Func type of this arity");
678 switch (typeArgs.Length) {
680 func = typeof (Func<>);
683 func = typeof (Func<,>);
686 func = typeof (Func<,,>);
689 func = typeof (Func<,,,>);
692 func = typeof (Func<,,,,>);
696 return func.MakeGenericType (typeArgs);
700 public static InvocationExpression Invoke (Expression expression, params Expression [] arguments)
702 throw new NotImplementedException ();
706 public static InvocationExpression Invoke (Expression expression, IEnumerable<Expression> arguments)
708 throw new NotImplementedException ();
712 public static Expression<TDelegate> Lambda<TDelegate> (Expression body, params ParameterExpression [] parameters)
714 throw new NotImplementedException ();
718 public static Expression<TDelegate> Lambda<TDelegate> (Expression body, IEnumerable<ParameterExpression> parameters)
720 throw new NotImplementedException ();
724 public static LambdaExpression Lambda (Expression body, params ParameterExpression [] parameters)
726 throw new NotImplementedException ();
730 public static LambdaExpression Lambda (Type delegateType, Expression body, params ParameterExpression [] parameters)
732 throw new NotImplementedException ();
736 public static LambdaExpression Lambda (Type delegateType, Expression body, IEnumerable<ParameterExpression> parameters)
738 throw new NotImplementedException ();
741 public static MemberListBinding ListBind (MemberInfo member, params ElementInit [] initializers)
743 throw new NotImplementedException ();
747 public static MemberListBinding ListBind (MemberInfo member, IEnumerable<ElementInit> initializers)
749 throw new NotImplementedException ();
753 public static MemberListBinding ListBind (MethodInfo propertyAccessor, params ElementInit [] initializers)
755 throw new NotImplementedException ();
759 public static MemberListBinding ListBind (MethodInfo propertyAccessor, IEnumerable<ElementInit> initializers)
761 throw new NotImplementedException ();
765 public static ListInitExpression ListInit (NewExpression newExpression, params ElementInit [] initializers)
767 throw new NotImplementedException ();
771 public static ListInitExpression ListInit (NewExpression newExpression, IEnumerable<ElementInit> initializers)
773 throw new NotImplementedException ();
777 public static ListInitExpression ListInit (NewExpression newExpression, params Expression [] initializers)
779 throw new NotImplementedException ();
783 public static ListInitExpression ListInit (NewExpression newExpression, IEnumerable<Expression> initializers)
785 throw new NotImplementedException ();
789 public static ListInitExpression ListInit (NewExpression newExpression, MethodInfo addMethod, params Expression [] initializers)
791 throw new NotImplementedException ();
795 public static ListInitExpression ListInit (NewExpression newExpression, MethodInfo addMethod, IEnumerable<Expression> initializers)
797 throw new NotImplementedException ();
801 public static MemberExpression MakeMemberAccess (Expression expression, MemberInfo member)
803 throw new NotImplementedException ();
806 public static UnaryExpression MakeUnary (ExpressionType unaryType, Expression operand, Type type)
808 return MakeUnary (unaryType, operand, type, null);
811 public static UnaryExpression MakeUnary (ExpressionType unaryType, Expression operand, Type type, MethodInfo method)
814 case ExpressionType.ArrayLength:
815 return ArrayLength (operand);
816 case ExpressionType.Convert:
817 return Convert (operand, type, method);
818 case ExpressionType.ConvertChecked:
819 return ConvertChecked (operand, type, method);
820 case ExpressionType.Negate:
821 return Negate (operand, method);
822 case ExpressionType.NegateChecked:
823 return NegateChecked (operand, method);
824 case ExpressionType.Not:
825 return Not (operand, method);
826 case ExpressionType.Quote:
827 return Quote (operand);
828 case ExpressionType.TypeAs:
829 return TypeAs (operand, type);
830 case ExpressionType.UnaryPlus:
831 return UnaryPlus (operand, method);
834 throw new ArgumentException ("MakeUnary expect an unary operator");
838 public static MemberMemberBinding MemberBind (MemberInfo member, params MemberBinding [] binding)
840 throw new NotImplementedException ();
844 public static MemberMemberBinding MemberBind (MemberInfo member, IEnumerable<MemberBinding> binding)
846 throw new NotImplementedException ();
850 public static MemberMemberBinding MemberBind (MethodInfo propertyAccessor, params MemberBinding [] binding)
852 throw new NotImplementedException ();
856 public static MemberMemberBinding MemberBind (MethodInfo propertyAccessor, IEnumerable<MemberBinding> binding)
858 throw new NotImplementedException ();
862 public static MemberInitExpression MemberInit (NewExpression newExpression, params MemberBinding [] binding)
864 throw new NotImplementedException ();
868 public static MemberInitExpression MemberInit (NewExpression newExpression, IEnumerable<MemberBinding> binding)
870 throw new NotImplementedException ();
874 public static UnaryExpression Negate (Expression expression)
876 throw new NotImplementedException ();
880 public static UnaryExpression Negate (Expression expression, MethodInfo method)
882 throw new NotImplementedException ();
886 public static UnaryExpression NegateChecked (Expression expression)
888 throw new NotImplementedException ();
892 public static UnaryExpression NegateChecked (Expression expression, MethodInfo method)
894 throw new NotImplementedException ();
898 public static NewExpression New (ConstructorInfo constructor)
900 throw new NotImplementedException ();
904 public static NewExpression New (Type type)
906 throw new NotImplementedException ();
910 public static NewExpression New (ConstructorInfo constructor, params Expression [] arguments)
912 throw new NotImplementedException ();
916 public static NewExpression New (ConstructorInfo constructor, IEnumerable<Expression> arguments)
918 throw new NotImplementedException ();
922 public static NewExpression New (ConstructorInfo constructor, IEnumerable<Expression> arguments, params MemberInfo [] members)
924 throw new NotImplementedException ();
928 public static NewExpression New (ConstructorInfo constructor, IEnumerable<Expression> arguments, IEnumerable<MemberInfo> members)
930 throw new NotImplementedException ();
934 public static NewArrayExpression NewArrayBounds (Type type, params Expression [] bounds)
936 throw new NotImplementedException ();
940 public static NewArrayExpression NewArrayBounds (Type type, IEnumerable<Expression> bounds)
942 throw new NotImplementedException ();
946 public static NewArrayExpression NewArrayInit (Type type, params Expression [] bounds)
948 throw new NotImplementedException ();
952 public static NewArrayExpression NewArrayInit (Type type, IEnumerable<Expression> bounds)
954 throw new NotImplementedException ();
958 public static UnaryExpression Not (Expression expression)
960 throw new NotImplementedException ();
964 public static UnaryExpression Not (Expression expression, MethodInfo method)
966 throw new NotImplementedException ();
970 public static ParameterExpression Parameter (Type type, string name)
972 throw new NotImplementedException ();
976 public static MemberExpression Property (Expression expression, MethodInfo propertyAccessor)
978 throw new NotImplementedException ();
982 public static MemberExpression Property (Expression expression, PropertyInfo property)
984 throw new NotImplementedException ();
988 public static MemberExpression Property (Expression expression, string propertyName)
990 throw new NotImplementedException ();
994 public static MemberExpression PropertyOrField (Expression expression, string propertyOrFieldName)
996 throw new NotImplementedException ();
999 public static UnaryExpression Quote (Expression expression)
1001 if (expression == null)
1002 throw new ArgumentNullException ("expression");
1004 return new UnaryExpression (ExpressionType.Quote, expression, expression.GetType ());
1007 public static UnaryExpression TypeAs (Expression expression, Type type)
1009 if (expression == null)
1010 throw new ArgumentNullException ("expression");
1012 throw new ArgumentNullException ("type");
1013 if (type.IsValueType && !IsNullable (type))
1014 throw new ArgumentException ("TypeAs expect a reference or a nullable type");
1016 return new UnaryExpression (ExpressionType.TypeAs, expression, type);
1019 public static TypeBinaryExpression TypeIs (Expression expression, Type type)
1021 if (expression == null)
1022 throw new ArgumentNullException ("expression");
1024 throw new ArgumentNullException ("type");
1026 return new TypeBinaryExpression (ExpressionType.TypeIs, expression, type, typeof (bool));
1030 public static UnaryExpression UnaryPlus (Expression expression)
1032 throw new NotImplementedException ();
1036 public static UnaryExpression UnaryPlus (Expression expression, MethodInfo method)
1038 throw new NotImplementedException ();
1041 static bool IsNullable (Type type)
1043 return type.IsGenericType && type.GetGenericTypeDefinition () == typeof (Nullable<>);