1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Microsoft Public License. A
6 * copy of the license can be found in the License.html file at the root of this distribution. If
7 * you cannot locate the Microsoft Public License, please send an email to
8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
9 * by the terms of the Microsoft Public License.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
15 using System; using Microsoft;
19 using System.Dynamic.Utils;
20 using System.Linq.Expressions;
22 using Microsoft.Scripting.Utils;
23 using Microsoft.Linq.Expressions;
27 namespace System.Dynamic {
29 namespace Microsoft.Scripting {
32 /// Represents the unary dynamic operation at the call site, providing the binding semantic and the details about the operation.
34 public abstract class UnaryOperationBinder : DynamicMetaObjectBinder {
35 private ExpressionType _operation;
38 /// Initializes a new instance of the <see cref="BinaryOperationBinder"/> class.
40 /// <param name="operation">The unary operation kind.</param>
41 protected UnaryOperationBinder(ExpressionType operation) {
42 ContractUtils.Requires(OperationIsValid(operation), "operation");
43 _operation = operation;
47 /// The result type of the operation.
49 public override sealed Type ReturnType {
52 case ExpressionType.IsFalse:
53 case ExpressionType.IsTrue:
56 return typeof(object);
62 /// The unary operation kind.
64 public ExpressionType Operation {
71 /// Performs the binding of the unary dynamic operation if the target dynamic object cannot bind.
73 /// <param name="target">The target of the dynamic unary operation.</param>
74 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
75 public DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target) {
76 return FallbackUnaryOperation(target, null);
80 /// Performs the binding of the unary dynamic operation if the target dynamic object cannot bind.
82 /// <param name="target">The target of the dynamic unary operation.</param>
83 /// <param name="errorSuggestion">The binding result in case the binding fails, or null.</param>
84 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
85 public abstract DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target, DynamicMetaObject errorSuggestion);
88 /// Performs the binding of the dynamic unary operation.
90 /// <param name="target">The target of the dynamic operation.</param>
91 /// <param name="args">An array of arguments of the dynamic operation.</param>
92 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
93 public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
94 ContractUtils.RequiresNotNull(target, "target");
95 ContractUtils.Requires(args == null || args.Length == 0, "args");
97 return target.BindUnaryOperation(this);
100 // this is a standard DynamicMetaObjectBinder
101 internal override sealed bool IsStandardBinder {
107 internal static bool OperationIsValid(ExpressionType operation) {
109 #region Generated Unary Operation Binder Validator
111 // *** BEGIN GENERATED CODE ***
112 // generated by function: gen_unop_validator from: generate_tree.py
114 case ExpressionType.Negate:
115 case ExpressionType.UnaryPlus:
116 case ExpressionType.Not:
117 case ExpressionType.Decrement:
118 case ExpressionType.Increment:
119 case ExpressionType.OnesComplement:
120 case ExpressionType.IsTrue:
121 case ExpressionType.IsFalse:
123 // *** END GENERATED CODE ***
127 case ExpressionType.Extension: