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;
21 using System.Linq.Expressions;
23 using System.Dynamic.Utils;
25 using Microsoft.Linq.Expressions;
26 using Microsoft.Scripting;
27 using Microsoft.Scripting.Utils;
29 using System.Diagnostics;
32 namespace System.Dynamic {
34 namespace Microsoft.Scripting {
37 // ComFallbackMetaObject just delegates everything to the binder.
39 // Note that before performing FallBack on a ComObject we need to unwrap it so that
40 // binder would act upon the actual object (typically Rcw)
42 // Also: we don't need to implement these for any operations other than those
43 // supported by ComBinder
44 internal class ComFallbackMetaObject : DynamicMetaObject {
45 internal ComFallbackMetaObject(Expression expression, BindingRestrictions restrictions, object arg)
46 : base(expression, restrictions, arg) {
49 public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes) {
50 ContractUtils.RequiresNotNull(binder, "binder");
51 return binder.FallbackGetIndex(UnwrapSelf(), indexes);
54 public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) {
55 ContractUtils.RequiresNotNull(binder, "binder");
56 return binder.FallbackSetIndex(UnwrapSelf(), indexes, value);
59 public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
60 ContractUtils.RequiresNotNull(binder, "binder");
61 return binder.FallbackGetMember(UnwrapSelf());
64 public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args) {
65 ContractUtils.RequiresNotNull(binder, "binder");
66 return binder.FallbackInvokeMember(UnwrapSelf(), args);
69 public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value) {
70 ContractUtils.RequiresNotNull(binder, "binder");
71 return binder.FallbackSetMember(UnwrapSelf(), value);
74 protected virtual ComUnwrappedMetaObject UnwrapSelf() {
75 return new ComUnwrappedMetaObject(
76 ComObject.RcwFromComObject(Expression),
77 Restrictions.Merge(ComBinderHelpers.GetTypeRestrictionForDynamicMetaObject(this)),
78 ((ComObject)Value).RuntimeCallableWrapper
83 // This type exists as a signal type, so ComBinder knows not to try to bind
84 // again when we're trying to fall back
85 internal sealed class ComUnwrappedMetaObject : DynamicMetaObject {
86 internal ComUnwrappedMetaObject(Expression expression, BindingRestrictions restrictions, object value)
87 : base(expression, restrictions, value) {