private DynamicMetaObject IncrDecr(DynamicMetaObject target, int valueToAdd, DynamicMetaObject errorSuggestion)
 {
     if (!target.HasValue)
     {
         return(base.Defer(target, new DynamicMetaObject[0]));
     }
     if ((target.Value is PSObject) && (PSObject.Base(target.Value) != target.Value))
     {
         return(this.DeferForPSObject(new DynamicMetaObject[] { target }));
     }
     if (target.Value == null)
     {
         return(new DynamicMetaObject(ExpressionCache.Constant(valueToAdd).Cast(typeof(object)), target.PSGetTypeRestriction()));
     }
     if (target.LimitType.IsNumeric())
     {
         DynamicMetaObject arg = new DynamicMetaObject(ExpressionCache.Constant(valueToAdd), BindingRestrictions.Empty, valueToAdd);
         return(new DynamicMetaObject(PSBinaryOperationBinder.Get(ExpressionType.Add, true, false).FallbackBinaryOperation(target, arg, errorSuggestion).Expression, target.PSGetTypeRestriction()));
     }
     return(errorSuggestion ?? target.ThrowRuntimeError(new DynamicMetaObject[0], BindingRestrictions.Empty, "OperatorRequiresNumber", ParserStrings.OperatorRequiresNumber, new Expression[] { Expression.Constant(((base.Operation == ExpressionType.Increment) ? TokenKind.PlusPlus : TokenKind.MinusMinus).Text()), Expression.Constant(target.LimitType) }));
 }
Esempio n. 2
0
        public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
        {
            Expression          expression3;
            BindingRestrictions expressionRestriction;

            if (!target.HasValue)
            {
                return(base.Defer(target, new DynamicMetaObject[0]).WriteToDebugLog(this));
            }
            IList      list       = target.Value as IList;
            Expression expression = target.Expression;

            if (!typeof(IList).Equals(expression.Type))
            {
                expression = Expression.Convert(expression, typeof(IList));
            }
            MemberExpression left = Expression.Property(Expression.Convert(expression, typeof(ICollection)), CachedReflectionInfo.ICollection_Count);

            switch (list.Count)
            {
            case 0:
                expression3           = ExpressionCache.Constant(false);
                expressionRestriction = BindingRestrictions.GetExpressionRestriction(Expression.Equal(left, ExpressionCache.Constant(0)));
                break;

            case 1:
                expression3           = Expression.Call(expression, CachedReflectionInfo.IList_get_Item, new Expression[] { ExpressionCache.Constant(0) }).Convert(typeof(bool));
                expressionRestriction = BindingRestrictions.GetExpressionRestriction(Expression.Equal(left, ExpressionCache.Constant(1)));
                break;

            default:
                expression3           = ExpressionCache.Constant(true);
                expressionRestriction = BindingRestrictions.GetExpressionRestriction(Expression.GreaterThan(left, ExpressionCache.Constant(1)));
                break;
            }
            return(new DynamicMetaObject(expression3, expressionRestriction).WriteToDebugLog(this));
        }
Esempio n. 3
0
 public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
 {
     if (!target.HasValue || !args[0].HasValue)
     {
         DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[2];
         dynamicMetaObjectArray[0] = args[0];
         dynamicMetaObjectArray[1] = args[1];
         return(base.Defer(target, dynamicMetaObjectArray).WriteToDebugLog(this));
     }
     else
     {
         BindingRestrictions bindingRestriction = target.PSGetTypeRestriction();
         if (target.Value as PSObject == null)
         {
             if (target.Value != null)
             {
                 if (target.Value as ScriptBlock == null)
                 {
                     Expression        expression        = args[1].Expression;
                     DynamicExpression dynamicExpression = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), args[0].Expression, expression);
                     if (target.Value as Regex != null || (this._flags & SwitchFlags.Regex) != SwitchFlags.None)
                     {
                         MethodCallExpression methodCallExpression = Expression.Call(CachedReflectionInfo.SwitchOps_ConditionSatisfiedRegex, ExpressionCache.Constant((this._flags & SwitchFlags.CaseSensitive) != SwitchFlags.None), target.Expression.Cast(typeof(object)), ExpressionCache.NullExtent, dynamicExpression, expression);
                         return(new DynamicMetaObject(methodCallExpression, bindingRestriction).WriteToDebugLog(this));
                     }
                     else
                     {
                         if (target.Value as WildcardPattern != null || (this._flags & SwitchFlags.Wildcard) != SwitchFlags.None)
                         {
                             MethodCallExpression methodCallExpression1 = Expression.Call(CachedReflectionInfo.SwitchOps_ConditionSatisfiedWildcard, ExpressionCache.Constant((this._flags & SwitchFlags.CaseSensitive) != SwitchFlags.None), target.Expression.Cast(typeof(object)), dynamicExpression, expression);
                             return(new DynamicMetaObject(methodCallExpression1, bindingRestriction).WriteToDebugLog(this));
                         }
                         else
                         {
                             DynamicExpression dynamicExpression1 = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), target.Expression, expression);
                             return(new DynamicMetaObject(Compiler.CallStringEquals(dynamicExpression1, dynamicExpression, (this._flags & SwitchFlags.CaseSensitive) == SwitchFlags.None), bindingRestriction).WriteToDebugLog(this));
                         }
                     }
                 }
                 else
                 {
                     Expression[] automationNullConstant = new Expression[6];
                     automationNullConstant[0] = ExpressionCache.Constant(true);
                     automationNullConstant[1] = Expression.Constant(ScriptBlock.ErrorHandlingBehavior.WriteToExternalErrorPipe);
                     automationNullConstant[2] = args[0].CastOrConvert(typeof(object));
                     automationNullConstant[3] = ExpressionCache.AutomationNullConstant;
                     automationNullConstant[4] = ExpressionCache.AutomationNullConstant;
                     automationNullConstant[5] = ExpressionCache.NullObjectArray;
                     MethodCallExpression methodCallExpression2 = Expression.Call(target.Expression.Cast(typeof(ScriptBlock)), CachedReflectionInfo.ScriptBlock_DoInvokeReturnAsIs, automationNullConstant);
                     return(new DynamicMetaObject(Expression.Dynamic(PSConvertBinder.Get(typeof(bool)), typeof(bool), methodCallExpression2), bindingRestriction).WriteToDebugLog(this));
                 }
             }
             else
             {
                 return(new DynamicMetaObject(Expression.Equal(args[0].Expression.Cast(typeof(object)), ExpressionCache.NullConstant), target.PSGetTypeRestriction()).WriteToDebugLog(this));
             }
         }
         else
         {
             return(new DynamicMetaObject(Expression.Dynamic(this, this.ReturnType, Expression.Call(CachedReflectionInfo.PSObject_Base, target.Expression.Cast(typeof(object))), args[0].Expression, args[1].Expression), bindingRestriction).WriteToDebugLog(this));
         }
     }
 }
Esempio n. 4
0
        public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
        {
            if (!target.HasValue)
            {
                return(base.Defer(target, args));
            }
            if (target.Value == AutomationNull.Value)
            {
                return(new DynamicMetaObject(Expression.Block(typeof(void), new Expression[] { Expression.Call(CachedReflectionInfo.PipelineOps_Nop, new Expression[0]) }), BindingRestrictions.GetInstanceRestriction(target.Expression, AutomationNull.Value)).WriteToDebugLog(this));
            }
            DynamicMetaObject obj2 = PSEnumerableBinder.IsEnumerable(target);

            if (obj2 == null)
            {
                DynamicMetaObject   obj3         = PSVariableAssignmentBinder.Get().Bind(target, new DynamicMetaObject[0]);
                BindingRestrictions restrictions = target.LimitType.IsValueType ? obj3.Restrictions : target.PSGetTypeRestriction();
                return(new DynamicMetaObject(Expression.Call(args[0].Expression, CachedReflectionInfo.Pipe_Add, new Expression[] { obj3.Expression.Cast(typeof(object)) }), restrictions).WriteToDebugLog(this));
            }
            bool b = !(PSObject.Base(target.Value) is IEnumerator);

            return(new DynamicMetaObject(Expression.Call(CachedReflectionInfo.EnumerableOps_WriteEnumerableToPipe, obj2.Expression, args[0].Expression, args[1].Expression, ExpressionCache.Constant(b)), obj2.Restrictions).WriteToDebugLog(this));
        }
        private DynamicMetaObject UnaryPlus(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
        {
            if (!target.HasValue)
            {
                return(base.Defer(target, new DynamicMetaObject[0]));
            }
            if ((target.Value is PSObject) && (PSObject.Base(target.Value) != target.Value))
            {
                return(this.DeferForPSObject(new DynamicMetaObject[] { target }));
            }
            if (!target.LimitType.IsNumeric())
            {
                return(new DynamicMetaObject(Expression.Dynamic(PSBinaryOperationBinder.Get(ExpressionType.Add, true, false), typeof(object), ExpressionCache.Constant(0), target.Expression), target.PSGetTypeRestriction()));
            }
            Expression expr = target.Expression.Cast(target.LimitType);

            if (target.LimitType.Equals(typeof(byte)) || target.LimitType.Equals(typeof(sbyte)))
            {
                expr = expr.Cast(typeof(int));
            }
            return(new DynamicMetaObject(Expression.UnaryPlus(expr).Cast(typeof(object)), target.PSGetTypeRestriction()));
        }
        internal DynamicMetaObject BNot(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
        {
            if (!target.HasValue)
            {
                return(base.Defer(target, new DynamicMetaObject[0]));
            }
            if ((target.Value is PSObject) && (PSObject.Base(target.Value) != target.Value))
            {
                return(this.DeferForPSObject(new DynamicMetaObject[] { target }));
            }
            if (target.Value == null)
            {
                return(new DynamicMetaObject(ExpressionCache.Constant(-1).Cast(typeof(object)), target.PSGetTypeRestriction()));
            }
            MethodInfo method = target.LimitType.GetMethod("op_OnesComplement", BindingFlags.Public | BindingFlags.Static, null, new Type[] { target.LimitType }, null);

            if (method != null)
            {
                return(new DynamicMetaObject(Expression.OnesComplement(target.Expression.Cast(target.LimitType), method).Cast(typeof(object)), target.PSGetTypeRestriction()));
            }
            if (target.LimitType.Equals(typeof(string)))
            {
                return(new DynamicMetaObject(Expression.Dynamic(this, this.ReturnType, PSBinaryOperationBinder.ConvertStringToNumber(target.Expression, typeof(int))), target.PSGetTypeRestriction()));
            }
            Expression expression = null;

            if (!target.LimitType.IsNumeric())
            {
                bool flag;
                Type resultType = typeof(int);
                LanguagePrimitives.ConversionData conversion = LanguagePrimitives.FigureConversion(target.Value, resultType, out flag);
                if (conversion.Rank != ConversionRank.None)
                {
                    expression = PSConvertBinder.InvokeConverter(conversion, target.Expression, resultType, flag, ExpressionCache.InvariantCulture);
                }
                else
                {
                    resultType = typeof(long);
                    conversion = LanguagePrimitives.FigureConversion(target.Value, resultType, out flag);
                    if (conversion.Rank != ConversionRank.None)
                    {
                        expression = PSConvertBinder.InvokeConverter(conversion, target.Expression, resultType, flag, ExpressionCache.InvariantCulture);
                    }
                }
            }
            else
            {
                TypeCode typeCode = LanguagePrimitives.GetTypeCode(target.LimitType);
                if (typeCode < TypeCode.Int32)
                {
                    expression = target.Expression.Cast(typeof(int));
                }
                else if (typeCode <= TypeCode.UInt64)
                {
                    expression = target.Expression.Cast(target.LimitType);
                }
                else
                {
                    Type type2 = (typeCode == TypeCode.Decimal) ? typeof(DecimalOps) : typeof(DoubleOps);
                    Type type  = (typeCode == TypeCode.Decimal) ? typeof(decimal) : typeof(double);
                    return(new DynamicMetaObject(Expression.Call(type2.GetMethod("BNot", BindingFlags.NonPublic | BindingFlags.Static), target.Expression.Convert(type)), target.PSGetTypeRestriction()));
                }
            }
            if ((expression == null) && (errorSuggestion == null))
            {
                return(PSConvertBinder.ThrowNoConversion(target, typeof(int), this, -1, new DynamicMetaObject[0]));
            }
            return(new DynamicMetaObject(Expression.OnesComplement(expression).Cast(typeof(object)), target.PSGetTypeRestriction()));
        }
        public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
        {
            int i;

            if (target.HasValue)
            {
                if (target.Value as PSObject == null || PSObject.Base(target.Value) == target.Value)
                {
                    IList value = target.Value as IList;
                    if (value == null)
                    {
                        return(new DynamicMetaObject(Expression.NewArrayInit(typeof(object), Enumerable.Repeat <Expression>(ExpressionCache.NullConstant, this._elements - 1).Prepend <Expression>(target.Expression.Cast(typeof(object)))), target.PSGetTypeRestriction()).WriteToDebugLog(this));
                    }
                    else
                    {
                        MemberExpression    memberExpression   = Expression.Property(target.Expression.Cast(typeof(ICollection)), CachedReflectionInfo.ICollection_Count);
                        BindingRestrictions bindingRestriction = target.PSGetTypeRestriction().Merge(BindingRestrictions.GetExpressionRestriction(Expression.Equal(memberExpression, ExpressionCache.Constant(value.Count))));
                        if (value.Count != this._elements)
                        {
                            Expression[]        nullConstant        = new Expression[this._elements];
                            ParameterExpression parameterExpression = Expression.Variable(typeof(IList));
                            if (value.Count >= this._elements)
                            {
                                for (i = 0; i < this._elements - 1; i++)
                                {
                                    Expression[] expressionArray = new Expression[1];
                                    expressionArray[0] = ExpressionCache.Constant(i);
                                    nullConstant[i]    = Expression.Call(parameterExpression, CachedReflectionInfo.IList_get_Item, expressionArray);
                                }
                                nullConstant[this._elements - 1] = Expression.Call(CachedReflectionInfo.EnumerableOps_GetSlice, parameterExpression, ExpressionCache.Constant(this._elements - 1)).Cast(typeof(object));
                            }
                            else
                            {
                                for (i = 0; i < value.Count; i++)
                                {
                                    Expression[] expressionArray1 = new Expression[1];
                                    expressionArray1[0] = ExpressionCache.Constant(i);
                                    nullConstant[i]     = Expression.Call(parameterExpression, CachedReflectionInfo.IList_get_Item, expressionArray1);
                                }
                                while (i < this._elements)
                                {
                                    nullConstant[i] = ExpressionCache.NullConstant;
                                    i++;
                                }
                            }
                            ParameterExpression[] parameterExpressionArray = new ParameterExpression[1];
                            parameterExpressionArray[0] = parameterExpression;
                            Expression[] expressionArray2 = new Expression[2];
                            expressionArray2[0] = Expression.Assign(parameterExpression, target.Expression.Cast(typeof(IList)));
                            expressionArray2[1] = Expression.NewArrayInit(typeof(object), nullConstant);
                            return(new DynamicMetaObject(Expression.Block(parameterExpressionArray, expressionArray2), bindingRestriction).WriteToDebugLog(this));
                        }
                        else
                        {
                            return(new DynamicMetaObject(target.Expression.Cast(typeof(IList)), bindingRestriction).WriteToDebugLog(this));
                        }
                    }
                }
                else
                {
                    DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
                    dynamicMetaObjectArray[0] = target;
                    return(this.DeferForPSObject(dynamicMetaObjectArray).WriteToDebugLog(this));
                }
            }
            else
            {
                return(base.Defer(target, new DynamicMetaObject[0]).WriteToDebugLog(this));
            }
        }
Esempio n. 8
0
        private DynamicMetaObject SetIndexMultiDimensionArray(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
        {
            Type       elementType = target.LimitType.GetElementType();
            Expression expression  = PSGetIndexBinder.ConvertIndex(value, elementType);

            if (expression != null)
            {
                if ((int)indexes.Length != 1)
                {
                    Array arrays = (Array)target.Value;
                    if ((int)indexes.Length == arrays.Rank)
                    {
                        Expression[] expressionArray = new Expression[(int)indexes.Length];
                        int          num             = 0;
                        while (num < (int)indexes.Length)
                        {
                            expressionArray[num] = PSGetIndexBinder.ConvertIndex(indexes[num], typeof(int));
                            if (expressionArray[num] != null)
                            {
                                num++;
                            }
                            else
                            {
                                DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
                                dynamicMetaObjectArray[0] = indexes[num];
                                return(PSConvertBinder.ThrowNoConversion(indexes[num], typeof(int), this, this._version, indexes.Except <DynamicMetaObject>(dynamicMetaObjectArray).Append <DynamicMetaObject>(target).Append <DynamicMetaObject>(value).ToArray <DynamicMetaObject>()));
                            }
                        }
                        return(new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_SetMDArrayValue, target.Expression.Cast(typeof(Array)), Expression.NewArrayInit(typeof(int), expressionArray), expression.Cast(typeof(object))), target.CombineRestrictions(indexes).Merge(value.PSGetTypeRestriction())));
                    }
                    else
                    {
                        DynamicMetaObject dynamicMetaObject  = errorSuggestion;
                        DynamicMetaObject dynamicMetaObject1 = dynamicMetaObject;
                        if (dynamicMetaObject == null)
                        {
                            DynamicMetaObject   dynamicMetaObject2      = target;
                            DynamicMetaObject[] dynamicMetaObjectArray1 = indexes;
                            BindingRestrictions bindingRestriction      = value.PSGetTypeRestriction();
                            string       str = "NeedMultidimensionalIndex";
                            string       needMultidimensionalIndex = ParserStrings.NeedMultidimensionalIndex;
                            Expression[] expressionArray1          = new Expression[2];
                            expressionArray1[0] = ExpressionCache.Constant(arrays.Rank);
                            Expression[]        expressionArray2           = expressionArray1;
                            int                 num1                       = 1;
                            MethodInfo          arrayOpsIndexStringMessage = CachedReflectionInfo.ArrayOps_IndexStringMessage;
                            Type                type                       = typeof(object);
                            DynamicMetaObject[] dynamicMetaObjectArray2    = indexes;
                            expressionArray2[num1] = Expression.Call(arrayOpsIndexStringMessage, Expression.NewArrayInit(type, dynamicMetaObjectArray2.Select <DynamicMetaObject, Expression>((DynamicMetaObject i) => i.Expression.Cast(typeof(object)))));
                            dynamicMetaObject1     = dynamicMetaObject2.ThrowRuntimeError(dynamicMetaObjectArray1, bindingRestriction, str, needMultidimensionalIndex, expressionArray1);
                        }
                        return(dynamicMetaObject1);
                    }
                }
                else
                {
                    Expression expression1 = PSGetIndexBinder.ConvertIndex(indexes[0], typeof(int[]));
                    if (expression1 != null)
                    {
                        return(new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_SetMDArrayValue, target.Expression.Cast(typeof(Array)), expression1, expression.Cast(typeof(object))), target.CombineRestrictions(indexes).Merge(value.PSGetTypeRestriction())));
                    }
                    else
                    {
                        DynamicMetaObject dynamicMetaObject3 = errorSuggestion;
                        DynamicMetaObject dynamicMetaObject4 = dynamicMetaObject3;
                        if (dynamicMetaObject3 == null)
                        {
                            DynamicMetaObject[] dynamicMetaObjectArray3 = new DynamicMetaObject[2];
                            dynamicMetaObjectArray3[0] = target;
                            dynamicMetaObjectArray3[1] = value;
                            dynamicMetaObject4         = PSConvertBinder.ThrowNoConversion(indexes[0], typeof(int[]), this, this._version, dynamicMetaObjectArray3);
                        }
                        return(dynamicMetaObject4);
                    }
                }
            }
            else
            {
                DynamicMetaObject dynamicMetaObject5 = errorSuggestion;
                DynamicMetaObject dynamicMetaObject6 = dynamicMetaObject5;
                if (dynamicMetaObject5 == null)
                {
                    dynamicMetaObject6 = PSConvertBinder.ThrowNoConversion(value, elementType, this, this._version, indexes.Prepend <DynamicMetaObject>(target).ToArray <DynamicMetaObject>());
                }
                return(dynamicMetaObject6);
            }
        }
Esempio n. 9
0
        internal static Expression InvokeConverter(LanguagePrimitives.ConversionData conversion, Expression value, Type resultType, bool debase, Expression formatProvider)
        {
            Expression expression;

            if ((conversion.Rank == ConversionRank.Identity) || (conversion.Rank == ConversionRank.Assignable))
            {
                expression = debase ? Expression.Call(CachedReflectionInfo.PSObject_Base, value) : value;
            }
            else
            {
                Expression expression2;
                Expression nullPSObject;
                if (debase)
                {
                    expression2  = Expression.Call(CachedReflectionInfo.PSObject_Base, value);
                    nullPSObject = value.Cast(typeof(PSObject));
                }
                else
                {
                    expression2  = value.Cast(typeof(object));
                    nullPSObject = ExpressionCache.NullPSObject;
                }
                expression = Expression.Call(Expression.Constant(conversion.Converter), conversion.Converter.GetType().GetMethod("Invoke"), new Expression[] { expression2, Expression.Constant(resultType), ExpressionCache.Constant(true), nullPSObject, formatProvider, ExpressionCache.NullTypeTable });
            }
            if (expression.Type.Equals(resultType) || resultType.Equals(typeof(LanguagePrimitives.InternalPSCustomObject)))
            {
                return(expression);
            }
            if (resultType.IsValueType && (Nullable.GetUnderlyingType(resultType) == null))
            {
                return(Expression.Unbox(expression, resultType));
            }
            return(Expression.Convert(expression, resultType));
        }
Esempio n. 10
0
 private DynamicMetaObject PropertyDoesntExist(DynamicMetaObject target, BindingRestrictions restrictions)
 {
     if (!this._nonEnumerating && (target.Value != AutomationNull.Value))
     {
         DynamicMetaObject obj2 = PSEnumerableBinder.IsEnumerable(target);
         if (obj2 != null)
         {
             return(new DynamicMetaObject(Expression.Call(CachedReflectionInfo.EnumerableOps_PropertyGetter, Expression.Constant(this.GetNonEnumeratingBinder()), obj2.Expression), restrictions));
         }
     }
     if (base.Name.Equals("Length", StringComparison.OrdinalIgnoreCase) || base.Name.Equals("Count", StringComparison.OrdinalIgnoreCase))
     {
         int i = (PSObject.Base(target.Value) == null) ? 0 : 1;
         return(new DynamicMetaObject(Expression.Condition(Compiler.IsStrictMode(2, null), this.ThrowPropertyNotFoundStrict(), ExpressionCache.Constant(i).Cast(typeof(object))), restrictions));
     }
     return(new DynamicMetaObject(Expression.Condition(Compiler.IsStrictMode(2, null), this.ThrowPropertyNotFoundStrict(), this._nonEnumerating ? ExpressionCache.AutomationNullConstant : ExpressionCache.NullConstant), restrictions));
 }
 internal static BindingRestrictions GetVersionCheck(int expectedVersionNumber)
 {
     return(BindingRestrictions.GetExpressionRestriction(Expression.Equal(Expression.Field(null, CachedReflectionInfo.PSVariableAssignmentBinder__mutableValueWithInstanceMemberVersion), ExpressionCache.Constant(expectedVersionNumber))));
 }
Esempio n. 12
0
        private DynamicMetaObject IndexWithNegativeChecks(DynamicMetaObject target, DynamicMetaObject index, PropertyInfo lengthProperty, Func <Expression, Expression, Expression> generateIndexOperation)
        {
            ParameterExpression expression2;
            ParameterExpression expression3;
            ParameterExpression left = Expression.Parameter(target.LimitType, "target");
            Expression          expr = Expression.Block(new ParameterExpression[] { left, expression2 = Expression.Parameter(typeof(int), "len"), expression3 = Expression.Parameter(typeof(int), "index") }, new Expression[] { Expression.Assign(left, target.Expression.Cast(target.LimitType)), Expression.Assign(expression2, Expression.Property(left, lengthProperty)), Expression.Assign(expression3, index.Expression), Expression.IfThen(Expression.LessThan(expression3, ExpressionCache.Constant(0)), Expression.Assign(expression3, Expression.Add(expression3, expression2))), generateIndexOperation(left, expression3) });

            return(new DynamicMetaObject(this.SafeIndexResult(expr), target.CombineRestrictions(new DynamicMetaObject[] { index })));
        }
Esempio n. 13
0
        private DynamicMetaObject GetIndexMultiDimensionArray(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion)
        {
            Array array = (Array)target.Value;

            if (indexes.Length == 1)
            {
                if (PSEnumerableBinder.IsEnumerable(indexes[0]) == null)
                {
                    return(target.ThrowRuntimeError(indexes, BindingRestrictions.Empty, "NeedMultidimensionalIndex", ParserStrings.NeedMultidimensionalIndex, new Expression[] { ExpressionCache.Constant(array.Rank), Expression.Dynamic(PSToStringBinder.Get(), typeof(string), indexes[0].Expression, ExpressionCache.GetExecutionContextFromTLS) }));
                }
                return(new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_GetMDArrayValueOrSlice, Expression.Convert(target.Expression, typeof(Array)), indexes[0].Expression.Cast(typeof(object))), target.CombineRestrictions(indexes)));
            }
            IEnumerable <Expression> source = from index in indexes
                                              select ConvertIndex(index, typeof(int)) into i
                                                  where i != null
                                              select i;

            if (source.Count <Expression>() == indexes.Length)
            {
                return(new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_GetMDArrayValue, Expression.Convert(target.Expression, typeof(Array)), Expression.NewArrayInit(typeof(int), source), ExpressionCache.Constant(!this._allowSlicing)), target.CombineRestrictions(indexes)));
            }
            if (this._allowSlicing)
            {
                return(this.InvokeSlicingIndexer(target, indexes));
            }
            return(errorSuggestion ?? this.CannotIndexTarget(target, indexes));
        }
Esempio n. 14
0
        public override Expression Reduce()
        {
            List <Expression> expressions = new List <Expression>();

            if (this._debugSymbolDocument != null)
            {
                expressions.Add(Expression.DebugInfo(this._debugSymbolDocument, this._extent.StartLineNumber, this._extent.StartColumnNumber, this._extent.EndLineNumber, this._extent.EndColumnNumber));
            }
            expressions.Add(Expression.Assign(Expression.Field(Compiler._functionContext, CachedReflectionInfo.FunctionContext__currentSequencePointIndex), ExpressionCache.Constant(this._sequencePoint)));
            if (this._checkBreakpoints)
            {
                expressions.Add(Expression.IfThen(Expression.GreaterThan(Expression.Field(Compiler._executionContextParameter, CachedReflectionInfo.ExecutionContext_DebuggingMode), ExpressionCache.Constant(0)), Expression.Call(Expression.Field(Compiler._executionContextParameter, CachedReflectionInfo.ExecutionContext_Debugger), CachedReflectionInfo.Debugger_OnSequencePointHit, new Expression[] { Compiler._functionContext })));
            }
            expressions.Add(ExpressionCache.Empty);
            return(Expression.Block(expressions));
        }
Esempio n. 15
0
        private DynamicMetaObject InvokeDotNetMethod(DynamicMetaObject target, DynamicMetaObject[] args, BindingRestrictions restrictions, MethodInformation[] mi, Type errorExceptionType)
        {
            bool   flag = false;
            object obj;
            string str    = null;
            string str1   = null;
            int    length = (int)args.Length;

            if (this._propertySetter)
            {
                length--;
            }
            object[] objArray = new object[length];
            for (int i = 0; i < length; i++)
            {
                object   value     = args[i].Value;
                object[] objArray1 = objArray;
                int      num       = i;
                if (value == AutomationNull.Value)
                {
                    obj = null;
                }
                else
                {
                    obj = value;
                }
                objArray1[num] = obj;
            }
            MethodInformation methodInformation = Adapter.FindBestMethod(mi, this._invocationConstraints, objArray, ref str, ref str1, out flag);

            if (methodInformation == null)
            {
                Type[] typeArray = new Type[4];
                typeArray[0] = typeof(string);
                typeArray[1] = typeof(Exception);
                typeArray[2] = typeof(string);
                typeArray[3] = typeof(object[]);
                object[] objArray2 = new object[4];
                objArray2[0] = str;
                objArray2[2] = str1;
                object[] name = new object[2];
                name[0]      = base.Name;
                name[1]      = base.CallInfo.ArgumentCount;
                objArray2[3] = name;
                return(new DynamicMetaObject(Compiler.CreateThrow(typeof(object), errorExceptionType, typeArray, objArray2), restrictions));
            }
            else
            {
                MethodInfo methodInfo = (MethodInfo)methodInformation.method;
                Expression expression = PSInvokeMemberBinder.InvokeMethod(methodInfo, target, args, flag);
                if (expression.Type.Equals(typeof(void)))
                {
                    expression = Expression.Block(expression, ExpressionCache.AutomationNullConstant);
                }
                if ((!(methodInfo.DeclaringType == typeof(SteppablePipeline)) || !methodInfo.Name.Equals("Begin", StringComparison.Ordinal)) && !methodInfo.Name.Equals("Process", StringComparison.Ordinal) && !methodInfo.Name.Equals("End", StringComparison.Ordinal))
                {
                    ParameterExpression parameterExpression = Expression.Variable(typeof(Exception));
                    CatchBlock[]        catchBlockArray     = new CatchBlock[1];
                    catchBlockArray[0] = Expression.Catch(parameterExpression, Expression.Block(Expression.Call(CachedReflectionInfo.ExceptionHandlingOps_ConvertToMethodInvocationException, parameterExpression, Expression.Constant(errorExceptionType), Expression.Constant(methodInfo.Name), ExpressionCache.Constant((int)args.Length), Expression.Constant(methodInfo)), Expression.Rethrow(typeof(object))));
                    expression         = Expression.TryCatch(expression.Cast(typeof(object)), catchBlockArray);
                    return(new DynamicMetaObject(expression, restrictions));
                }
                else
                {
                    return(new DynamicMetaObject(expression, restrictions));
                }
            }
        }
Esempio n. 16
0
 internal static BindingRestrictions GetVersionCheck(DynamicMetaObjectBinder binder, int expectedVersionNumber)
 {
     return(BindingRestrictions.GetExpressionRestriction(Expression.Equal(Expression.Field(Expression.Constant(binder), "_version"), ExpressionCache.Constant(expectedVersionNumber))));
 }
Esempio n. 17
0
        private DynamicMetaObject IndexWithNegativeChecks(DynamicMetaObject target, DynamicMetaObject index, DynamicMetaObject value, PropertyInfo lengthProperty, Func <Expression, Expression, Expression, Expression> generateIndexOperation)
        {
            DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
            dynamicMetaObjectArray[0] = index;
            BindingRestrictions bindingRestriction = target.CombineRestrictions(dynamicMetaObjectArray).Merge(value.Restrictions);

            bindingRestriction = bindingRestriction.Merge(BinderUtils.GetOptionalVersionAndLanguageCheckForType(this, target.LimitType, this._version));
            ParameterExpression parameterExpression  = Expression.Parameter(target.LimitType, "target");
            ParameterExpression parameterExpression1 = Expression.Parameter(typeof(int), "len");
            Expression          expression           = value.Expression;
            ParameterExpression parameterExpression2 = Expression.Parameter(expression.Type, "value");
            ParameterExpression parameterExpression3 = Expression.Parameter(typeof(int), "index");

            ParameterExpression[] parameterExpressionArray = new ParameterExpression[4];
            parameterExpressionArray[0] = parameterExpression;
            parameterExpressionArray[1] = parameterExpression2;
            parameterExpressionArray[2] = parameterExpression1;
            parameterExpressionArray[3] = parameterExpression3;
            Expression[] expressionArray = new Expression[7];
            expressionArray[0] = Expression.Assign(parameterExpression, target.Expression.Cast(target.LimitType));
            expressionArray[1] = Expression.Assign(parameterExpression2, expression);
            expressionArray[2] = Expression.Assign(parameterExpression1, Expression.Property(parameterExpression, lengthProperty));
            expressionArray[3] = Expression.Assign(parameterExpression3, index.Expression);
            expressionArray[4] = Expression.IfThen(Expression.LessThan(parameterExpression3, ExpressionCache.Constant(0)), Expression.Assign(parameterExpression3, Expression.Add(parameterExpression3, parameterExpression1)));
            expressionArray[5] = generateIndexOperation(parameterExpression, parameterExpression3, parameterExpression2);
            expressionArray[6] = parameterExpression2.Cast(typeof(object));
            return(new DynamicMetaObject(Expression.Block(parameterExpressionArray, expressionArray), bindingRestriction));
        }
Esempio n. 18
0
        public Expression SetValue(Compiler compiler, Expression rhs)
        {
            ParameterExpression left = Expression.Variable(rhs.Type);
            int count = this.ArrayLiteral.Elements.Count;
            List <Expression> expressions = new List <Expression> {
                Expression.Assign(left, rhs)
            };

            for (int i = 0; i < count; i++)
            {
                Expression      expression2    = Expression.Call(left, CachedReflectionInfo.IList_get_Item, new Expression[] { ExpressionCache.Constant(i) });
                ExpressionAst   ast            = this.ArrayLiteral.Elements[i];
                ArrayLiteralAst pureExpression = ast as ArrayLiteralAst;
                if (ast is ParenExpressionAst)
                {
                    pureExpression = ((ParenExpressionAst)ast).Pipeline.GetPureExpression() as ArrayLiteralAst;
                }
                if (pureExpression != null)
                {
                    expression2 = Expression.Dynamic(PSArrayAssignmentRHSBinder.Get(pureExpression.Elements.Count), typeof(IList), expression2);
                }
                expressions.Add(compiler.ReduceAssignment((ISupportsAssignment)ast, TokenKind.Equals, expression2));
            }
            expressions.Add(left);
            return(Expression.Block(new ParameterExpression[] { left }, expressions));
        }
Esempio n. 19
0
        public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
        {
            PSMemberInfo        info;
            BindingRestrictions restrictions2;
            bool flag3;
            Type type4;

            if (!target.HasValue || !value.HasValue)
            {
                return(base.Defer(target, new DynamicMetaObject[] { value }));
            }
            object obj2 = PSObject.Base(target.Value);

            if (obj2 == null)
            {
                return(target.ThrowRuntimeError(new DynamicMetaObject[] { value }, BindingRestrictions.Empty, "PropertyNotFound", ParserStrings.PropertyNotFound, new Expression[] { Expression.Constant(base.Name) }).WriteToDebugLog(this));
            }
            if (value.Value == AutomationNull.Value)
            {
                value = new DynamicMetaObject(ExpressionCache.NullConstant, value.PSGetTypeRestriction(), null);
            }
            if (this._getMemberBinder.HasInstanceMember && PSGetMemberBinder.TryGetInstanceMember(target.Value, base.Name, out info))
            {
                ParameterExpression   expression   = Expression.Variable(typeof(PSMemberInfo));
                ParameterExpression   expression2  = Expression.Variable(typeof(object));
                ConditionalExpression expression3  = Expression.Condition(Expression.Call(CachedReflectionInfo.PSGetMemberBinder_TryGetInstanceMember, target.Expression.Cast(typeof(object)), Expression.Constant(base.Name), expression), Expression.Assign(Expression.Property(expression, "Value"), value.Expression.Cast(typeof(object))), base.GetUpdateExpression(typeof(object)));
                BindingRestrictions   restrictions = BinderUtils.GetVersionCheck(this._getMemberBinder, this._getMemberBinder._version).Merge(value.PSGetTypeRestriction());
                return(new DynamicMetaObject(Expression.Block(new ParameterExpression[] { expression, expression2 }, new Expression[] { expression3 }), restrictions).WriteToDebugLog(this));
            }
            if (obj2 is IDictionary)
            {
                Type genericTypeArg = null;
                bool flag           = PSGetMemberBinder.IsGenericDictionary(obj2, ref genericTypeArg);
                if (!flag || (genericTypeArg != null))
                {
                    bool                flag2;
                    Type                type       = flag ? typeof(IDictionary <,>).MakeGenericType(new Type[] { typeof(string), genericTypeArg }) : typeof(IDictionary);
                    MethodInfo          method     = type.GetMethod("set_Item");
                    ParameterExpression left       = Expression.Variable(genericTypeArg ?? typeof(object));
                    Type                resultType = left.Type;
                    LanguagePrimitives.ConversionData conversion = LanguagePrimitives.FigureConversion(value.Value, resultType, out flag2);
                    if (conversion.Rank != ConversionRank.None)
                    {
                        Expression right = PSConvertBinder.InvokeConverter(conversion, value.Expression, resultType, flag2, ExpressionCache.InvariantCulture);
                        return(new DynamicMetaObject(Expression.Block(new ParameterExpression[] { left }, new Expression[] { Expression.Assign(left, right), Expression.Call(PSGetMemberBinder.GetTargetExpr(target).Cast(type), method, Expression.Constant(base.Name), right), right.Cast(typeof(object)) }), target.CombineRestrictions(new DynamicMetaObject[] { value })).WriteToDebugLog(this));
                    }
                }
            }
            info          = this._getMemberBinder.GetPSMemberInfo(target, out restrictions2, out flag3, out type4, null, null);
            restrictions2 = restrictions2.Merge(value.PSGetTypeRestriction());
            if (ExecutionContext.HasEverUsedConstrainedLanguage)
            {
                restrictions2 = restrictions2.Merge(BinderUtils.GetLanguageModeCheckIfHasEverUsedConstrainedLanguage());
                DynamicMetaObject obj3 = PSGetMemberBinder.EnsureAllowedInLanguageMode(LocalPipeline.GetExecutionContextFromTLS().LanguageMode, target, obj2, base.Name, this._static, new DynamicMetaObject[] { value }, restrictions2, "PropertySetterNotSupportedInConstrainedLanguage", ParserStrings.PropertySetConstrainedLanguage);
                if (obj3 != null)
                {
                    return(obj3.WriteToDebugLog(this));
                }
            }
            if (flag3)
            {
                if (info == null)
                {
                    return((errorSuggestion ?? new DynamicMetaObject(Compiler.ThrowRuntimeError("PropertyAssignmentException", ParserStrings.PropertyNotFound, this.ReturnType, new Expression[] { Expression.Constant(base.Name) }), restrictions2)).WriteToDebugLog(this));
                }
                PSPropertyInfo info3 = info as PSPropertyInfo;
                if (info3 != null)
                {
                    if (!info3.IsSettable)
                    {
                        Expression innerException = Expression.New(CachedReflectionInfo.SetValueException_ctor, new Expression[] { Expression.Constant("PropertyAssignmentException"), Expression.Constant(null, typeof(Exception)), Expression.Constant(ParserStrings.PropertyIsReadOnly), Expression.NewArrayInit(typeof(object), new Expression[] { Expression.Constant(base.Name) }) });
                        return(new DynamicMetaObject(Compiler.ThrowRuntimeErrorWithInnerException("PropertyAssignmentException", Expression.Constant(ParserStrings.PropertyIsReadOnly), innerException, this.ReturnType, new Expression[] { Expression.Constant(base.Name) }), restrictions2).WriteToDebugLog(this));
                    }
                    PSProperty property = info3 as PSProperty;
                    if (property != null)
                    {
                        DotNetAdapter.PropertyCacheEntry adapterData = property.adapterData as DotNetAdapter.PropertyCacheEntry;
                        if (adapterData != null)
                        {
                            Expression expression10;
                            Type       propertyType;
                            if (adapterData.member.DeclaringType.IsGenericTypeDefinition)
                            {
                                Expression expression9 = Expression.New(CachedReflectionInfo.SetValueException_ctor, new Expression[] { Expression.Constant("PropertyAssignmentException"), Expression.Constant(null, typeof(Exception)), Expression.Constant(ExtendedTypeSystem.CannotInvokeStaticMethodOnUninstantiatedGenericType), Expression.NewArrayInit(typeof(object), new Expression[] { Expression.Constant(adapterData.member.DeclaringType.FullName) }) });
                                return(new DynamicMetaObject(Compiler.ThrowRuntimeErrorWithInnerException("PropertyAssignmentException", Expression.Constant(ExtendedTypeSystem.CannotInvokeStaticMethodOnUninstantiatedGenericType), expression9, this.ReturnType, new Expression[] { Expression.Constant(adapterData.member.DeclaringType.FullName) }), restrictions2).WriteToDebugLog(this));
                            }
                            PropertyInfo member = adapterData.member as PropertyInfo;
                            if (member != null)
                            {
                                propertyType = member.PropertyType;
                                Expression expression11 = this._static ? null : PSGetMemberBinder.GetTargetExpr(target);
                                expression10 = Expression.Property(expression11, member);
                            }
                            else
                            {
                                FieldInfo field = (FieldInfo)adapterData.member;
                                propertyType = field.FieldType;
                                Expression expression12 = this._static ? null : PSGetMemberBinder.GetTargetExpr(target);
                                expression10 = Expression.Field(expression12, field);
                            }
                            Type underlyingType = Nullable.GetUnderlyingType(propertyType);
                            Type type7          = underlyingType ?? propertyType;
                            ParameterExpression expression13 = Expression.Variable(type7);
                            Expression          expression14 = (underlyingType != null) ? ((value.Value == null) ? ((Expression)Expression.Constant(null, propertyType)) : ((Expression)Expression.New(propertyType.GetConstructor(new Type[] { underlyingType }), new Expression[] { expression13 }))) : ((Expression)expression13);
                            Expression          expression15 = (type7.Equals(typeof(object)) && value.LimitType.Equals(typeof(PSObject))) ? Expression.Call(CachedReflectionInfo.PSObject_Base, value.Expression.Cast(typeof(PSObject))) : value.CastOrConvert(type7);
                            Expression          expr         = Expression.Block(new ParameterExpression[] { expression13 }, new Expression[] { Expression.Assign(expression13, expression15), Expression.Assign(expression10, expression14), expression13.Cast(typeof(object)) });
                            ParameterExpression variable     = Expression.Variable(typeof(Exception));
                            return(new DynamicMetaObject(Expression.TryCatch(expr.Cast(typeof(object)), new CatchBlock[] { Expression.Catch(variable, Expression.Block(Expression.Call(CachedReflectionInfo.ExceptionHandlingOps_ConvertToMethodInvocationException, variable, Expression.Constant(typeof(SetValueInvocationException)), Expression.Constant(base.Name), ExpressionCache.Constant(0), Expression.Constant(null, typeof(MemberInfo))), Expression.Rethrow(typeof(object)))) }), restrictions2).WriteToDebugLog(this));
                        }
                    }
                    PSCodeProperty property2 = info3 as PSCodeProperty;
                    if (property2 != null)
                    {
                        ParameterExpression expression17 = Expression.Variable(typeof(object));
                        return(new DynamicMetaObject(Expression.Block(new ParameterExpression[] { expression17 }, new Expression[] { Expression.Assign(expression17, value.CastOrConvert(expression17.Type)), PSInvokeMemberBinder.InvokeMethod(property2.SetterCodeReference, null, new DynamicMetaObject[] { target, value }, false), expression17 }), restrictions2).WriteToDebugLog(this));
                    }
                    PSScriptProperty property3 = info3 as PSScriptProperty;
                    if (property3 != null)
                    {
                        return(new DynamicMetaObject(Expression.Call(Expression.Constant(property3), CachedReflectionInfo.PSScriptProperty_InvokeSetter, PSGetMemberBinder.GetTargetExpr(target), value.Expression.Cast(typeof(object))), restrictions2).WriteToDebugLog(this));
                    }
                }
                if (errorSuggestion != null)
                {
                    return(errorSuggestion.WriteToDebugLog(this));
                }
            }
            return(new DynamicMetaObject(Expression.Call(CachedReflectionInfo.PSSetMemberBinder_SetAdaptedValue, PSGetMemberBinder.GetTargetExpr(target).Cast(typeof(object)), Expression.Constant(base.Name), value.Expression.Cast(typeof(object))), restrictions2).WriteToDebugLog(this));
        }
Esempio n. 20
0
        public override DynamicMetaObject FallbackCreateInstance(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
        {
            bool flag;
            Type type = (Type)target.Value;

            MethodInformation[] methodInformationArray = DotNetAdapter.GetMethodInformationArray(type.GetConstructors());
            target = new DynamicMetaObject(target.Expression, BindingRestrictions.GetInstanceRestriction(target.Expression, target.Value), target.Value);
            string            errorId     = null;
            string            errorMsg    = null;
            int               count       = base.CallInfo.ArgumentCount - base.CallInfo.ArgumentNames.Count;
            MethodInformation information = Adapter.FindBestMethod(methodInformationArray, null, (from arg in args.Take <DynamicMetaObject>(count) select arg.Value).ToArray <object>(), ref errorId, ref errorMsg, out flag);

            if (information == null)
            {
                if (errorSuggestion == null)
                {
                }
                return(new DynamicMetaObject(Expression.Throw(Expression.New(CachedReflectionInfo.MethodException_ctor, new Expression[] { Expression.Constant(errorId), Expression.Constant(null, typeof(Exception)), Expression.Constant(errorMsg), Expression.NewArrayInit(typeof(object), new Expression[] { Expression.Constant(".ctor").Cast(typeof(object)), ExpressionCache.Constant(count).Cast(typeof(object)) }) }), this.ReturnType), target.CombineRestrictions(args)));
            }
            ConstructorInfo method = (ConstructorInfo)information.method;

            ParameterInfo[] parameters = method.GetParameters();
            Expression[]    arguments  = new Expression[parameters.Length];
            int             index      = 0;

            while (index < parameters.Length)
            {
                bool flag3;
                Type parameterType = parameters[index].ParameterType;
                if (parameters[index].GetCustomAttributes(typeof(ParamArrayAttribute), true).Any <object>() && flag)
                {
                    Type elementType = parameters[index].ParameterType.GetElementType();
                    List <Expression> initializers = new List <Expression>();
                    int num3 = index;
                    int num4 = index;
                    while (num4 < count)
                    {
                        bool flag2;
                        LanguagePrimitives.ConversionData data = LanguagePrimitives.FigureConversion(args[index].Value, elementType, out flag2);
                        initializers.Add(PSConvertBinder.InvokeConverter(data, args[num4].Expression, elementType, flag2, ExpressionCache.InvariantCulture));
                        num4++;
                        index++;
                    }
                    arguments[num3] = Expression.NewArrayInit(elementType, initializers);
                    break;
                }
                LanguagePrimitives.ConversionData conversion = LanguagePrimitives.FigureConversion(args[index].Value, parameterType, out flag3);
                arguments[index] = PSConvertBinder.InvokeConverter(conversion, args[index].Expression, parameterType, flag3, ExpressionCache.InvariantCulture);
                index++;
            }
            Expression right = Expression.New(method, arguments);

            if (base.CallInfo.ArgumentNames.Any <string>())
            {
                ParameterExpression expr        = Expression.Parameter(right.Type);
                List <Expression>   expressions = new List <Expression>();
                foreach (string str3 in base.CallInfo.ArgumentNames)
                {
                    Expression   expression3;
                    Type         propertyType;
                    bool         flag4;
                    MemberInfo[] infoArray3 = type.GetMember(str3, MemberTypes.Property | MemberTypes.Field, BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
                    if ((infoArray3.Length != 1) || (!(infoArray3[0] is PropertyInfo) && !(infoArray3[0] is FieldInfo)))
                    {
                        return(target.ThrowRuntimeError(args, BindingRestrictions.Empty, "PropertyNotFoundForType", ParserStrings.PropertyNotFoundForType, new Expression[] { Expression.Constant(str3), Expression.Constant(type) }));
                    }
                    MemberInfo info2 = infoArray3[0];
                    if (info2 is PropertyInfo)
                    {
                        PropertyInfo property = (PropertyInfo)info2;
                        if (property.GetSetMethod() == null)
                        {
                            return(target.ThrowRuntimeError(args, BindingRestrictions.Empty, "PropertyIsReadOnly", ParserStrings.PropertyIsReadOnly, new Expression[] { Expression.Constant(str3) }));
                        }
                        propertyType = property.PropertyType;
                        expression3  = Expression.Property(expr.Cast(info2.DeclaringType), property);
                    }
                    else
                    {
                        propertyType = ((FieldInfo)info2).FieldType;
                        expression3  = Expression.Field(expr.Cast(info2.DeclaringType), (FieldInfo)info2);
                    }
                    LanguagePrimitives.ConversionData data3 = LanguagePrimitives.FigureConversion(args[index].Value, propertyType, out flag4);
                    if (data3.Rank == ConversionRank.None)
                    {
                        return(PSConvertBinder.ThrowNoConversion(args[index], propertyType, this, -1, args.Except <DynamicMetaObject>(new DynamicMetaObject[] { args[index] }).Prepend <DynamicMetaObject>(target).ToArray <DynamicMetaObject>()));
                    }
                    expressions.Add(Expression.Assign(expression3, PSConvertBinder.InvokeConverter(data3, args[index].Expression, propertyType, flag4, ExpressionCache.InvariantCulture)));
                    index++;
                }
                ParameterExpression variable    = Expression.Parameter(typeof(Exception));
                BlockExpression     expression5 = Expression.Block(Expression.Assign(expr, right), Expression.TryCatch(Expression.Block(typeof(void), expressions), new CatchBlock[] { Expression.Catch(variable, Expression.Block(Expression.Call(CachedReflectionInfo.CommandProcessorBase_CheckForSevereException, variable), Compiler.ThrowRuntimeErrorWithInnerException("PropertyAssignmentException", Expression.Property(variable, "Message"), variable, typeof(void), new Expression[0]))) }), expr);
                right = Expression.Block(new ParameterExpression[] { expr }, new Expression[] { expression5 });
            }
            return(new DynamicMetaObject(right, target.CombineRestrictions(args)));
        }