2018-02-13 09:23:53 -08:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
2016-03-30 14:20:52 -07:00
|
|
|
|
|
|
|
|
#if !SILVERLIGHT
|
|
|
|
|
#if !CLR2
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
#else
|
|
|
|
|
using Microsoft.Scripting.Ast;
|
|
|
|
|
#endif
|
|
|
|
|
using System.Dynamic;
|
|
|
|
|
|
|
|
|
|
//using Microsoft.Scripting.Utils;
|
|
|
|
|
|
2016-07-29 13:02:49 -07:00
|
|
|
namespace System.Management.Automation.ComInterop
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
// Note: we only need to support the operations used by ComBinder
|
2016-07-29 13:02:49 -07:00
|
|
|
internal class ComMetaObject : DynamicMetaObject
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
internal ComMetaObject(Expression expression, BindingRestrictions restrictions, object arg)
|
2016-07-29 13:02:49 -07:00
|
|
|
: base(expression, restrictions, arg)
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
}
|
|
|
|
|
|
2016-07-29 13:02:49 -07:00
|
|
|
public override DynamicMetaObject BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
return binder.Defer(args.AddFirst(WrapSelf()));
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 13:02:49 -07:00
|
|
|
public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
return binder.Defer(args.AddFirst(WrapSelf()));
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 13:02:49 -07:00
|
|
|
public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
return binder.Defer(WrapSelf());
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 13:02:49 -07:00
|
|
|
public override DynamicMetaObject BindSetMember(SetMemberBinder binder, DynamicMetaObject value)
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
return binder.Defer(WrapSelf(), value);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 13:02:49 -07:00
|
|
|
public override DynamicMetaObject BindGetIndex(GetIndexBinder binder, DynamicMetaObject[] indexes)
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
return binder.Defer(WrapSelf(), indexes);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 13:02:49 -07:00
|
|
|
public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value)
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
return binder.Defer(WrapSelf(), indexes.AddLast(value));
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-29 13:02:49 -07:00
|
|
|
private DynamicMetaObject WrapSelf()
|
|
|
|
|
{
|
2016-03-30 14:20:52 -07:00
|
|
|
return new DynamicMetaObject(
|
|
|
|
|
ComObject.RcwToComObject(Expression),
|
|
|
|
|
BindingRestrictions.GetExpressionRestriction(
|
|
|
|
|
Expression.Call(
|
|
|
|
|
typeof(ComObject).GetMethod("IsComObject", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic),
|
|
|
|
|
Helpers.Convert(Expression, typeof(object))
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|