Example #1
0
 internal object Invoke(PSMethodInvocationConstraints invocationConstraints, params object[] arguments)
 {
     if (arguments == null)
     {
         throw PSTraceSource.NewArgumentNullException("arguments");
     }
     return(this.adapter.BaseMethodInvoke(this, invocationConstraints, arguments));
 }
Example #2
0
 internal object Invoke(PSMethodInvocationConstraints invocationConstraints, params object[] arguments)
 {
     if (arguments == null)
     {
         throw PSTraceSource.NewArgumentNullException("arguments");
     }
     return this.adapter.BaseMethodInvoke(this, invocationConstraints, arguments);
 }
Example #3
0
 internal CallsiteSignature(Type targetType, PSMethodInvocationConstraints invocationConstraints, object[] arguments, CallsiteCacheEntryFlags flags)
 {
     this.targetType            = targetType;
     this.invocationConstraints = invocationConstraints;
     this.flags                  = flags;
     this.argumentTypes          = new Type[arguments.Length];
     this.effectiveArgumentTypes = new Type[arguments.Length];
     for (int i = 0; i < arguments.Length; i++)
     {
         this.argumentTypes[i]          = (arguments[i] == null) ? typeof(LanguagePrimitives.Null) : arguments[i].GetType();
         this.effectiveArgumentTypes[i] = Adapter.EffectiveArgumentType(arguments[i]);
     }
 }
Example #4
0
 public bool Equals(PSMethodInvocationConstraints other)
 {
     if (object.ReferenceEquals(null, other))
     {
         return(false);
     }
     if (!object.ReferenceEquals(this, other))
     {
         if (!object.Equals(other.MethodTargetType, this.MethodTargetType))
         {
             return(false);
         }
         if (!CallsiteSignature.EqualsForCollection <Type>(this.parameterTypes, other.parameterTypes))
         {
             return(false);
         }
     }
     return(true);
 }
 public bool Equals(PSMethodInvocationConstraints other)
 {
     if (object.ReferenceEquals(null, other))
     {
         return false;
     }
     if (!object.ReferenceEquals(this, other))
     {
         if (!object.Equals(other.MethodTargetType, this.MethodTargetType))
         {
             return false;
         }
         if (!CallsiteSignature.EqualsForCollection<Type>(this.parameterTypes, other.parameterTypes))
         {
             return false;
         }
     }
     return true;
 }
Example #6
0
 protected override object MethodInvoke(PSMethod method, PSMethodInvocationConstraints invocationConstraints, object[] arguments)
 {
     return(this.MethodInvoke(method, arguments));
 }
Example #7
0
 private PSGetIndexBinder(Tuple<CallInfo, PSMethodInvocationConstraints, bool> tuple) : base(tuple.Item1)
 {
     this._constraints = tuple.Item2;
     this._allowSlicing = tuple.Item3;
     this._version = 0;
 }
Example #8
0
 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;
     }
 }
Example #9
0
        internal static object CallMethod(IScriptExtent errorPosition, object target, string methodName, PSMethodInvocationConstraints invocationConstraints, object[] paramArray, bool callStatic, object valueToSet)
        {
            PSMethodInfo      staticCLRMember   = null;
            MethodInformation methodInformation = null;
            object            obj2 = null;
            PSObject          obj3 = null;
            Type   type;
            object obj4;

            if (LanguagePrimitives.IsNull(target))
            {
                throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), errorPosition, "InvokeMethodOnNull", ParserStrings.InvokeMethodOnNull, new object[0]);
            }
            obj2 = PSObject.Base(target);
            obj3 = PSObject.AsPSObject(target);
            CallsiteCacheEntryFlags none = CallsiteCacheEntryFlags.None;

            if (callStatic)
            {
                none |= CallsiteCacheEntryFlags.Static;
                type  = (Type)obj2;
            }
            else
            {
                type = obj2.GetType();
            }
            if (valueToSet != AutomationNull.Value)
            {
                none |= CallsiteCacheEntryFlags.ParameterizedSetter;
            }
            if (!obj3.isDeserialized)
            {
                methodInformation = Adapter.FindCachedMethod(type, methodName, invocationConstraints, paramArray, none);
            }
            if (methodInformation == null)
            {
                if (callStatic)
                {
                    staticCLRMember = PSObject.GetStaticCLRMember(target, methodName) as PSMethod;
                }
                else
                {
                    staticCLRMember = obj3.Members[methodName] as PSMethodInfo;
                }
                if (staticCLRMember == null)
                {
                    string fullName = null;
                    if (callStatic)
                    {
                        fullName = type.FullName;
                    }
                    else
                    {
                        fullName = GetTypeFullName(target);
                    }
                    if (valueToSet == AutomationNull.Value)
                    {
                        throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), errorPosition, "MethodNotFound", ParserStrings.MethodNotFound, new object[] { fullName, methodName });
                    }
                    throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), errorPosition, "ParameterizedPropertyAssignmentFailed", ParserStrings.ParameterizedPropertyAssignmentFailed, new object[] { fullName, methodName });
                }
            }
            try
            {
                if (methodInformation != null)
                {
                    object[] objArray;
                    PSObject.memberResolution.WriteLine("cache hit, Calling Method: {0}", new object[] { methodInformation.methodDefinition });
                    if (valueToSet != AutomationNull.Value)
                    {
                        DotNetAdapter.ParameterizedPropertyInvokeSet(methodName, obj2, valueToSet, new MethodInformation[] { methodInformation }, paramArray, false);
                        return(valueToSet);
                    }
                    MethodInformation[] methods = new MethodInformation[] { methodInformation };
                    Adapter.GetBestMethodAndArguments(methodName, methods, paramArray, out objArray);
                    return(DotNetAdapter.AuxiliaryMethodInvoke(obj2, objArray, methodInformation, paramArray));
                }
                if (valueToSet != AutomationNull.Value)
                {
                    PSParameterizedProperty property = staticCLRMember as PSParameterizedProperty;
                    if (property == null)
                    {
                        throw InterpreterError.NewInterpreterException(methodName, typeof(RuntimeException), errorPosition, "ParameterizedPropertyAssignmentFailed", ParserStrings.ParameterizedPropertyAssignmentFailed, new object[] { GetTypeFullName(target), methodName });
                    }
                    property.InvokeSet(valueToSet, paramArray);
                    return(valueToSet);
                }
                PSMethod method = staticCLRMember as PSMethod;
                if (method != null)
                {
                    return(method.Invoke(invocationConstraints, paramArray));
                }
                obj4 = staticCLRMember.Invoke(paramArray);
            }
            catch (MethodInvocationException exception)
            {
                if (exception.ErrorRecord.InvocationInfo == null)
                {
                    exception.ErrorRecord.SetInvocationInfo(new InvocationInfo(null, errorPosition));
                }
                throw;
            }
            catch (RuntimeException exception2)
            {
                if (exception2.ErrorRecord.InvocationInfo == null)
                {
                    exception2.ErrorRecord.SetInvocationInfo(new InvocationInfo(null, errorPosition));
                }
                throw;
            }
            catch (FlowControlException)
            {
                throw;
            }
            catch (ScriptCallDepthException)
            {
                throw;
            }
            catch (Exception exception3)
            {
                CommandProcessorBase.CheckForSevereException(exception3);
                throw InterpreterError.NewInterpreterExceptionByMessage(typeof(RuntimeException), errorPosition, exception3.Message, "MethodInvocationException", exception3);
            }
            return(obj4);
        }
Example #10
0
 internal static Expression InvokeMember(string name, PSMethodInvocationConstraints constraints, Expression target, IEnumerable<Expression> args, bool @static, bool propertySet)
 {
     return Expression.Dynamic(PSInvokeMemberBinder.Get(name, new CallInfo(args.Count<Expression>(), new string[0]), @static, propertySet, constraints), typeof(object), args.Prepend<Expression>(target));
 }
Example #11
0
 private PSSetIndexBinder(Tuple<CallInfo, PSMethodInvocationConstraints> tuple)
     : base(tuple.Item1)
 {
     this._constraints = tuple.Item2;
     this._version = 0;
 }
Example #12
0
 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;
 }