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 * ***************************************************************************/
16 using System.Dynamic.Utils;
18 namespace System.Dynamic {
20 /// Represents the convert dynamic operation at the call site, providing the binding semantic and the details about the operation.
22 public abstract class ConvertBinder : DynamicMetaObjectBinder {
23 private readonly Type _type;
24 private readonly bool _explicit;
27 /// Initializes a new intsance of the <see cref="ConvertBinder" />.
29 /// <param name="type">The type to convert to.</param>
30 /// <param name="explicit">true if the conversion should consider explicit conversions; otherwise, false.</param>
31 protected ConvertBinder(Type type, bool @explicit) {
32 ContractUtils.RequiresNotNull(type, "type");
35 _explicit = @explicit;
39 /// The type to convert to.
41 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
49 /// Gets the value indicating if the conversion should consider explicit conversions.
51 public bool Explicit {
58 /// Performs the binding of the dynamic convert operation if the target dynamic object cannot bind.
60 /// <param name="target">The target of the dynamic convert operation.</param>
61 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
62 public DynamicMetaObject FallbackConvert(DynamicMetaObject target) {
63 return FallbackConvert(target, null);
67 /// When overridden in the derived class, performs the binding of the dynamic convert operation if the target dynamic object cannot bind.
69 /// <param name="target">The target of the dynamic convert operation.</param>
70 /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
71 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
72 public abstract DynamicMetaObject FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion);
75 /// Performs the binding of the dynamic convert operation.
77 /// <param name="target">The target of the dynamic convert operation.</param>
78 /// <param name="args">An array of arguments of the dynamic convert operation.</param>
79 /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
80 public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
81 ContractUtils.RequiresNotNull(target, "target");
82 ContractUtils.Requires(args == null || args.Length == 0, "args");
84 return target.BindConvert(this);
87 // this is a standard DynamicMetaObjectBinder
88 internal override sealed bool IsStandardBinder {
95 /// The result type of the operation.
97 public override sealed Type ReturnType {