internal static MethodInfo FindBestMethod(DynamicMetaObject target, IEnumerable <DynamicMetaObject> args, string methodName, bool @static, PSMethodInvocationConstraints invocationConstraints) { bool flag = false; MethodInfo methodInfo = null; PSMethod dotNetMethod = PSObject.dotNetInstanceAdapter.GetDotNetMethod <PSMethod>(PSObject.Base(target.Value), methodName); if (dotNetMethod != null) { DotNetAdapter.MethodCacheEntry methodCacheEntry = (DotNetAdapter.MethodCacheEntry)dotNetMethod.adapterData; string str = null; string str1 = null; MethodInformation[] methodInformationArray = methodCacheEntry.methodInformationStructures; PSMethodInvocationConstraints pSMethodInvocationConstraint = invocationConstraints; IEnumerable <DynamicMetaObject> dynamicMetaObjects = args; MethodInformation methodInformation = Adapter.FindBestMethod(methodInformationArray, pSMethodInvocationConstraint, dynamicMetaObjects.Select <DynamicMetaObject, object>((DynamicMetaObject arg) => { if (arg.Value == AutomationNull.Value) { return(null); } else { return(arg.Value); } } ).ToArray <object>(), ref str, ref str1, out flag); if (methodInformation != null) { methodInfo = (MethodInfo)methodInformation.method; } } return(methodInfo); }
private PSInvokeMemberBinder(string name, bool ignoreCase, bool @static, bool propertySetter, bool nonEnumerating, CallInfo callInfo, PSMethodInvocationConstraints invocationConstraints) : base(name, ignoreCase, callInfo) { this._static = @static; this._propertySetter = propertySetter; this._nonEnumerating = nonEnumerating; this._invocationConstraints = invocationConstraints; this._getMemberBinder = PSGetMemberBinder.Get(name, @static); }
public Expression SetValue(Compiler compiler, Expression rhs) { PSMethodInvocationConstraints invokeMemberConstraints = Compiler.GetInvokeMemberConstraints(this.InvokeMemberExpressionAst); StringConstantExpressionAst member = this.InvokeMemberExpressionAst.Member as StringConstantExpressionAst; Expression targetExpr = this.GetTargetExpr(compiler); IEnumerable <Expression> argumentExprs = this.GetArgumentExprs(compiler); if (member == null) { throw new NotImplementedException("invoke method dynamic name"); } return(Compiler.InvokeMember(member.Value, invokeMemberConstraints, targetExpr, argumentExprs.Append <Expression>(rhs), false, true)); }
public static PSGetIndexBinder Get(int argCount, PSMethodInvocationConstraints constraints, bool allowSlicing = true) { lock (_binderCache) { PSGetIndexBinder binder; Tuple <CallInfo, PSMethodInvocationConstraints, bool> key = Tuple.Create <CallInfo, PSMethodInvocationConstraints, bool>(new CallInfo(argCount, new string[0]), constraints, allowSlicing); if (!_binderCache.TryGetValue(key, out binder)) { binder = new PSGetIndexBinder(key); _binderCache.Add(key, binder); } return(binder); } }
public static PSSetIndexBinder Get(int argCount, PSMethodInvocationConstraints constraints = null) { PSSetIndexBinder pSSetIndexBinder = null; PSSetIndexBinder pSSetIndexBinder1; lock (PSSetIndexBinder._binderCache) { Tuple <CallInfo, PSMethodInvocationConstraints> tuple = Tuple.Create <CallInfo, PSMethodInvocationConstraints>(new CallInfo(argCount, new string[0]), constraints); if (!PSSetIndexBinder._binderCache.TryGetValue(tuple, out pSSetIndexBinder)) { pSSetIndexBinder = new PSSetIndexBinder(tuple); PSSetIndexBinder._binderCache.Add(tuple, pSSetIndexBinder); } pSSetIndexBinder1 = pSSetIndexBinder; } return(pSSetIndexBinder1); }
public Expression SetValue(Compiler compiler, Expression rhs) { Expression expression3; ParameterExpression element = Expression.Variable(rhs.Type); ArrayLiteralAst index = this.IndexExpressionAst.Index as ArrayLiteralAst; PSMethodInvocationConstraints invocationConstraints = this.GetInvocationConstraints(); Expression targetExpr = this.GetTargetExpr(compiler); if (index != null) { expression3 = Expression.Dynamic(PSSetIndexBinder.Get(index.Elements.Count, invocationConstraints), typeof(object), index.Elements.Select <ExpressionAst, Expression>(new Func <ExpressionAst, Expression>(compiler.Compile)).Prepend <Expression>(targetExpr).Append <Expression>(element)); } else { expression3 = Expression.Dynamic(PSSetIndexBinder.Get(1, invocationConstraints), typeof(object), targetExpr, this.GetIndexExpr(compiler), element); } return(Expression.Block(new ParameterExpression[] { element }, new Expression[] { Expression.Assign(element, rhs), expression3, element })); }
public Expression GetValue(Compiler compiler, List <Expression> exprs, List <ParameterExpression> temps) { PSMethodInvocationConstraints invokeMemberConstraints = Compiler.GetInvokeMemberConstraints(this.InvokeMemberExpressionAst); Expression targetExpr = this.GetTargetExpr(compiler); this._targetExprTemp = Expression.Variable(targetExpr.Type); exprs.Add(Expression.Assign(this._targetExprTemp, targetExpr)); IEnumerable <Expression> argumentExprs = this.GetArgumentExprs(compiler); this._argExprTemps = (from arg in argumentExprs select Expression.Variable(arg.Type)).ToArray <ParameterExpression>(); exprs.AddRange((IEnumerable <Expression>)argumentExprs.Zip <Expression, ParameterExpression, BinaryExpression>(this._argExprTemps, (arg, temp) => Expression.Assign(temp, arg))); temps.Add(this._targetExprTemp); temps.AddRange(this._argExprTemps); StringConstantExpressionAst member = this.InvokeMemberExpressionAst.Member as StringConstantExpressionAst; if (member == null) { throw new NotImplementedException("invoke method dynamic name"); } return(Compiler.InvokeMember(member.Value, invokeMemberConstraints, this._targetExprTemp, this._argExprTemps, false, false)); }
public Expression GetValue(Compiler compiler, List <Expression> exprs, List <ParameterExpression> temps) { Expression right = compiler.Compile(this.IndexExpressionAst.Target); this._targetExprTemp = Expression.Variable(right.Type); temps.Add(this._targetExprTemp); exprs.Add(Expression.Assign(this._targetExprTemp, right)); ExpressionAst index = this.IndexExpressionAst.Index; ArrayLiteralAst ast2 = index as ArrayLiteralAst; PSMethodInvocationConstraints invocationConstraints = this.GetInvocationConstraints(); if (ast2 != null) { return(Expression.Dynamic(PSGetIndexBinder.Get(ast2.Elements.Count, invocationConstraints, true), typeof(object), ast2.Elements.Select <ExpressionAst, Expression>(new Func <ExpressionAst, Expression>(compiler.Compile)).Prepend <Expression>(this._targetExprTemp))); } Expression expression3 = compiler.Compile(index); this._indexExprTemp = Expression.Variable(expression3.Type); temps.Add(this._indexExprTemp); exprs.Add(Expression.Assign(this._indexExprTemp, expression3)); return(Expression.Dynamic(PSGetIndexBinder.Get(1, invocationConstraints, true), typeof(object), this._targetExprTemp, this._indexExprTemp)); }
private PSSetIndexBinder(Tuple <CallInfo, PSMethodInvocationConstraints> tuple) : base(tuple.Item1) { this._constraints = tuple.Item2; this._version = 0; }
private static PSInvokeMemberBinder Get(string memberName, CallInfo callInfo, bool @static, bool propertySetter, bool nonEnumerating, PSMethodInvocationConstraints constraints) { PSInvokeMemberBinder pSInvokeMemberBinder = null; Dictionary <Tuple <string, CallInfo, bool, bool, PSMethodInvocationConstraints>, PSInvokeMemberBinder> tuples; if (@static) { tuples = PSInvokeMemberBinder._staticBinderCache; } else { tuples = PSInvokeMemberBinder._binderCache; } Dictionary <Tuple <string, CallInfo, bool, bool, PSMethodInvocationConstraints>, PSInvokeMemberBinder> tuples1 = tuples; lock (tuples1) { Tuple <string, CallInfo, bool, bool, PSMethodInvocationConstraints> tuple = Tuple.Create <string, CallInfo, bool, bool, PSMethodInvocationConstraints>(memberName, callInfo, propertySetter, nonEnumerating, constraints); if (!tuples1.TryGetValue(tuple, out pSInvokeMemberBinder)) { pSInvokeMemberBinder = new PSInvokeMemberBinder(memberName, true, @static, propertySetter, nonEnumerating, callInfo, constraints); tuples1.Add(tuple, pSInvokeMemberBinder); } } return(pSInvokeMemberBinder); }
public static PSInvokeMemberBinder Get(string memberName, CallInfo callInfo, bool @static, bool propertySetter, PSMethodInvocationConstraints constraints) { return(PSInvokeMemberBinder.Get(memberName, callInfo, @static, propertySetter, false, constraints)); }
internal Expression InvokeDynamicMember(Expression memberNameExpr, PSMethodInvocationConstraints constraints, Expression target, IEnumerable<Expression> args, bool @static, bool propertySet) { var binder = PSInvokeDynamicMemberBinder.Get(new CallInfo(args.Count()), _memberFunctionType, @static, propertySet, constraints); return DynamicExpression.Dynamic(binder, typeof(object), args.Prepend(memberNameExpr).Prepend(target)); }
private Expression InvokeBaseCtorMethod(PSMethodInvocationConstraints constraints, Expression target, IEnumerable<Expression> args) { var callInfo = new CallInfo(args.Count()); var binder = PSInvokeBaseCtorBinder.Get(callInfo, constraints); return DynamicExpression.Dynamic(binder, typeof(object), args.Prepend(target)); }
internal Expression InvokeMember(string name, PSMethodInvocationConstraints constraints, Expression target, IEnumerable<Expression> args, bool @static, bool propertySet) { var callInfo = new CallInfo(args.Count()); var classScope = _memberFunctionType != null ? _memberFunctionType.Type : null; var binder = name.Equals("new", StringComparison.OrdinalIgnoreCase) && @static ? (CallSiteBinder)PSCreateInstanceBinder.Get(callInfo, constraints, publicTypeOnly: true) : PSInvokeMemberBinder.Get(name, callInfo, @static, propertySet, constraints, classScope); return DynamicExpression.Dynamic(binder, typeof(object), args.Prepend(target)); }
private PSGetIndexBinder(Tuple <CallInfo, PSMethodInvocationConstraints, bool> tuple) : base(tuple.Item1) { this._constraints = tuple.Item2; this._allowSlicing = tuple.Item3; this._version = 0; }