Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
ComFallbackMetaObject.cs74 linesDownload Raw Back to ComInterop
1// Licensed to the .NET Foundation under one or more agreements.2// The .NET Foundation licenses this file to you under the MIT license.3 4using System.Dynamic;5using System.Linq.Expressions;6 7namespace System.Management.Automation.ComInterop8{9    //10    // ComFallbackMetaObject just delegates everything to the binder.11    //12    // Note that before performing FallBack on a ComObject we need to unwrap it so that13    // binder would act upon the actual object (typically Rcw)14    //15    // Also: we don't need to implement these for any operations other than those16    // supported by ComBinder17    internal class ComFallbackMetaObject : DynamicMetaObject18    {19        internal ComFallbackMetaObject(Expression expression, BindingRestrictions restrictions, object arg)20            : base(expression, restrictions, arg)21        {22        }23 24        public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)25        {26            Requires.NotNull(binder);27            return binder.FallbackGetIndex(UnwrapSelf(), indexes);28        }29 30        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)31        {32            Requires.NotNull(binder);33            return binder.FallbackSetIndex(UnwrapSelf(), indexes, value);34        }35 36        public override DynamicMetaObject BindGetMember(GetMemberBinder binder)37        {38            Requires.NotNull(binder);39            return binder.FallbackGetMember(UnwrapSelf());40        }41 42        public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)43        {44            Requires.NotNull(binder);45            return binder.FallbackInvokeMember(UnwrapSelf(), args);46        }47 48        public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value)49        {50            Requires.NotNull(binder);51            return binder.FallbackSetMember(UnwrapSelf(), value);52        }53 54        protected virtual ComUnwrappedMetaObject UnwrapSelf()55        {56            return new ComUnwrappedMetaObject(57                ComObject.RcwFromComObject(Expression),58                Restrictions.Merge(ComBinderHelpers.GetTypeRestrictionForDynamicMetaObject(this)),59                ((ComObject)Value).RuntimeCallableWrapper60            );61        }62    }63 64    // This type exists as a signal type, so ComBinder knows not to try to bind65    // again when we're trying to fall back66    internal sealed class ComUnwrappedMetaObject : DynamicMetaObject67    {68        internal ComUnwrappedMetaObject(Expression expression, BindingRestrictions restrictions, object value)69            : base(expression, restrictions, value)70        {71        }72    }73}74