示例#1
0
 private DynamicMetaObject CannotIndexTarget(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value)
 {
     BindingRestrictions bindingRestriction = value.PSGetTypeRestriction();
     bindingRestriction = bindingRestriction.Merge(BinderUtils.GetVersionCheck(this, this._version));
     bindingRestriction = bindingRestriction.Merge(BinderUtils.GetLanguageModeCheckIfHasEverUsedConstrainedLanguage());
     Expression[] expressionArray = new Expression[1];
     expressionArray[0] = Expression.Constant(target.LimitType);
     return target.ThrowRuntimeError(indexes, bindingRestriction, "CannotIndex", ParserStrings.CannotIndex, expressionArray);
 }
示例#2
0
 public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
 {
     bool flag;
     if (!target.HasValue)
     {
         return base.Defer(target, new DynamicMetaObject[0]).WriteToDebugLog(this);
     }
     Type resultType = ((target.Value is OrderedDictionary) || (target.Value is Hashtable)) ? typeof(LanguagePrimitives.InternalPSCustomObject) : typeof(PSObject);
     return new DynamicMetaObject(PSConvertBinder.InvokeConverter(LanguagePrimitives.FigureConversion(target.Value, resultType, out flag), target.Expression, resultType, flag, ExpressionCache.InvariantCulture), target.PSGetTypeRestriction()).WriteToDebugLog(this);
 }
示例#3
0
 public override DynamicMetaObject FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
 {
     bool flag;
     if (!target.HasValue)
     {
         return base.Defer(target, new DynamicMetaObject[0]).WriteToDebugLog(this);
     }
     if (target.Value == AutomationNull.Value)
     {
         return new DynamicMetaObject(Expression.Default(base.Type), target.PSGetTypeRestriction()).WriteToDebugLog(this);
     }
     Type resultType = base.Type;
     LanguagePrimitives.ConversionData conversion = LanguagePrimitives.FigureConversion(target.Value, resultType, out flag);
     if ((errorSuggestion != null) && (target.Value is DynamicObject))
     {
         return errorSuggestion.WriteToDebugLog(this);
     }
     BindingRestrictions restrictions = target.PSGetTypeRestriction().Merge(BinderUtils.GetOptionalVersionAndLanguageCheckForType(this, resultType, this._version));
     return new DynamicMetaObject(InvokeConverter(conversion, target.Expression, resultType, flag, ExpressionCache.InvariantCulture), restrictions).WriteToDebugLog(this);
 }
示例#4
0
 public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
 {
     if (!target.HasValue)
     {
         return base.Defer(target, args);
     }
     if ((target.Value is PSObject) && (PSObject.Base(target.Value) != target.Value))
     {
         return this.DeferForPSObject(new DynamicMetaObject[] { target }).WriteToDebugLog(this);
     }
     DynamicMetaObject obj2 = PSEnumerableBinder.IsEnumerable(target);
     if (obj2 == null)
     {
         return new DynamicMetaObject(Expression.NewArrayInit(typeof(object), new Expression[] { target.Expression.Cast(typeof(object)) }), target.PSGetTypeRestriction()).WriteToDebugLog(this);
     }
     if (PSObject.Base(target.Value) is ArrayList)
     {
         return new DynamicMetaObject(Expression.Call(PSEnumerableBinder.MaybeDebase(this, e => e.Cast(typeof(ArrayList)), target), CachedReflectionInfo.ArrayList_ToArray), PSEnumerableBinder.GetRestrictions(target)).WriteToDebugLog(this);
     }
     return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.EnumerableOps_ToArray, obj2.Expression), target.PSGetTypeRestriction()).WriteToDebugLog(this);
 }
示例#5
0
 public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
 {
     if (!target.HasValue || !args[0].HasValue)
     {
         return base.Defer(target, args).WriteToDebugLog(this);
     }
     if ((target.Value is PSObject) && (PSObject.Base(target.Value) != target.Value))
     {
         return this.DeferForPSObject(new DynamicMetaObject[] { target, args[0] }).WriteToDebugLog(this);
     }
     BindingRestrictions restrictions = target.PSGetTypeRestriction();
     if (target.LimitType.Equals(typeof(string)))
     {
         return new DynamicMetaObject(target.Expression.Cast(typeof(string)), restrictions).WriteToDebugLog(this);
     }
     return new DynamicMetaObject(InvokeToString(args[0].Expression, target.Expression), restrictions).WriteToDebugLog(this);
 }
示例#6
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);
 }
示例#7
0
 public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
 {
     string str;
     Expression expression;
     BindingRestrictions restrictions;
     if (!target.HasValue || !args[0].HasValue)
     {
         return base.Defer(target, new DynamicMetaObject[] { args[0] }).WriteToDebugLog(this);
     }
     DynamicMetaObject obj2 = args[0];
     object obj3 = PSObject.Base(obj2.Value);
     if (obj3 is string)
     {
         str = (string) obj3;
         if (obj2.Value is PSObject)
         {
             expression = Expression.Call(CachedReflectionInfo.PSObject_Base, obj2.Expression).Cast(typeof(string));
         }
         else
         {
             expression = obj2.Expression.Cast(typeof(string));
         }
     }
     else
     {
         if (target.Value is IDictionary)
         {
             restrictions = target.PSGetTypeRestriction().Merge(BindingRestrictions.GetExpressionRestriction(Expression.Not(Expression.TypeIs(args[0].Expression, typeof(string)))));
             return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.PSGetDynamicMemberBinder_GetIDictionaryMember, target.Expression.Cast(typeof(IDictionary)), args[0].Expression.Cast(typeof(object))), restrictions).WriteToDebugLog(this);
         }
         str = PSObject.ToStringParser(null, obj3);
         expression = PSToStringBinder.InvokeToString(ExpressionCache.NullConstant, obj2.Expression);
     }
     DynamicMetaObject obj4 = PSGetMemberBinder.Get(str, this._static).FallbackGetMember(target);
     restrictions = obj4.Restrictions.Merge(args[0].PSGetTypeRestriction()).Merge(BindingRestrictions.GetExpressionRestriction(Expression.Call(CachedReflectionInfo.String_Equals, Expression.Constant(str), expression, ExpressionCache.Ordinal)));
     return new DynamicMetaObject(obj4.Expression, restrictions).WriteToDebugLog(this);
 }
示例#8
0
 private DynamicMetaObject BinarySubDivOrRem(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion, string numericOpMethodName, string implicitOpMethodName, string errorOperatorText)
 {
     if (target.Value == null)
     {
         target = new DynamicMetaObject(ExpressionCache.Constant(0), target.PSGetTypeRestriction(), (object)0);
     }
     if (target.LimitType.IsNumericOrPrimitive())
     {
         DynamicMetaObject argAsNumericOrPrimitive = PSBinaryOperationBinder.GetArgAsNumericOrPrimitive(arg, target.LimitType);
         if (argAsNumericOrPrimitive == null)
         {
             if (arg.LimitType.Equals(typeof(string)))
             {
                 return this.BinaryNumericStringOp(target, arg);
             }
         }
         else
         {
             return this.BinaryNumericOp(numericOpMethodName, target, argAsNumericOrPrimitive);
         }
     }
     if (!target.LimitType.Equals(typeof(string)))
     {
         return PSBinaryOperationBinder.CallImplicitOp(implicitOpMethodName, target, arg, errorOperatorText, errorSuggestion);
     }
     else
     {
         return this.BinaryNumericStringOp(target, arg);
     }
 }
示例#9
0
 private DynamicMetaObject BinaryMultiply(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion)
 {
     Expression expression;
     Expression expression1;
     if (target.Value != null)
     {
         if (target.LimitType.IsNumeric())
         {
             DynamicMetaObject argAsNumericOrPrimitive = PSBinaryOperationBinder.GetArgAsNumericOrPrimitive(arg, target.LimitType);
             if (argAsNumericOrPrimitive == null)
             {
                 if (arg.LimitType.Equals(typeof(string)))
                 {
                     return this.BinaryNumericStringOp(target, arg);
                 }
             }
             else
             {
                 return this.BinaryNumericOp("Multiply", target, argAsNumericOrPrimitive);
             }
         }
         if (!target.LimitType.Equals(typeof(string)))
         {
             DynamicMetaObject dynamicMetaObject = PSEnumerableBinder.IsEnumerable(target);
             if (dynamicMetaObject == null)
             {
                 return PSBinaryOperationBinder.CallImplicitOp("op_Multiply", target, arg, "*", errorSuggestion);
             }
             else
             {
                 if (arg.LimitType.Equals(typeof(string)))
                 {
                     expression = PSBinaryOperationBinder.ConvertStringToNumber(arg.Expression, typeof(int)).Convert(typeof(int));
                 }
                 else
                 {
                     expression = arg.CastOrConvert(typeof(int));
                 }
                 Expression expression2 = expression;
                 if (!target.LimitType.IsArray)
                 {
                     DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
                     dynamicMetaObjectArray[0] = arg;
                     return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.EnumerableOps_Multiply, dynamicMetaObject.Expression, expression2), target.CombineRestrictions(dynamicMetaObjectArray));
                 }
                 else
                 {
                     Type elementType = target.LimitType.GetElementType();
                     Type[] typeArray = new Type[1];
                     typeArray[0] = elementType;
                     DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1];
                     dynamicMetaObjectArray1[0] = arg;
                     return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_Multiply.MakeGenericMethod(typeArray), target.Expression.Cast(elementType.MakeArrayType()), expression2), target.CombineRestrictions(dynamicMetaObjectArray1));
                 }
             }
         }
         else
         {
             if (arg.LimitType.Equals(typeof(string)))
             {
                 expression1 = PSBinaryOperationBinder.ConvertStringToNumber(arg.Expression, typeof(int)).Convert(typeof(int));
             }
             else
             {
                 expression1 = arg.CastOrConvert(typeof(int));
             }
             Expression expression3 = expression1;
             DynamicMetaObject[] dynamicMetaObjectArray2 = new DynamicMetaObject[1];
             dynamicMetaObjectArray2[0] = arg;
             return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.StringOps_Multiply, target.Expression.Cast(typeof(string)), expression3), target.CombineRestrictions(dynamicMetaObjectArray2));
         }
     }
     else
     {
         return new DynamicMetaObject(ExpressionCache.NullConstant, target.PSGetTypeRestriction());
     }
 }
示例#10
0
 private DynamicMetaObject BinaryEqualityComparison(DynamicMetaObject target, DynamicMetaObject arg)
 {
     bool flag = false;
     Func<Expression, Expression> func;
     MethodInfo charOpsCompareIeq;
     Expression expression;
     if (base.Operation == ExpressionType.NotEqual)
     {
         func = new Func<Expression, Expression>(Expression.Not);
     }
     else
     {
         func = (Expression e) => e;
     }
     Func<Expression, Expression> func1 = func;
     if (!target.LimitType.Equals(typeof(string)))
     {
         if (target.LimitType.Equals(typeof(char)) && this._ignoreCase)
         {
             Expression expression1 = null;
             BindingRestrictions bindingRestriction = null;
             if (!arg.LimitType.Equals(typeof(char)))
             {
                 string value = arg.Value as string;
                 if (value != null && value.Length == 1)
                 {
                     Expression[] expressionArray = new Expression[1];
                     expressionArray[0] = ExpressionCache.Constant(0);
                     expression1 = Expression.Call(arg.Expression.Cast(typeof(string)), CachedReflectionInfo.String_get_Chars, expressionArray);
                     bindingRestriction = arg.PSGetTypeRestriction().Merge(BindingRestrictions.GetExpressionRestriction(Expression.Equal(Expression.Property(arg.Expression.Cast(typeof(string)), CachedReflectionInfo.String_Length), ExpressionCache.Constant(1))));
                 }
             }
             else
             {
                 expression1 = arg.Expression;
                 bindingRestriction = arg.PSGetTypeRestriction();
             }
             if (expression1 != null)
             {
                 if (base.Operation == ExpressionType.Equal)
                 {
                     charOpsCompareIeq = CachedReflectionInfo.CharOps_CompareIeq;
                 }
                 else
                 {
                     charOpsCompareIeq = CachedReflectionInfo.CharOps_CompareIne;
                 }
                 return new DynamicMetaObject(Expression.Call(charOpsCompareIeq, target.Expression.Cast(typeof(char)), expression1.Cast(typeof(char))), target.PSGetTypeRestriction().Merge(bindingRestriction));
             }
         }
         Expression[] expressionArray1 = new Expression[1];
         expressionArray1[0] = arg.Expression.Cast(typeof(object));
         Expression expression2 = Expression.Call(target.Expression.Cast(typeof(object)), CachedReflectionInfo.Object_Equals, expressionArray1);
         Type limitType = target.LimitType;
         LanguagePrimitives.ConversionData conversionDatum = LanguagePrimitives.FigureConversion(arg.Value, limitType, out flag);
         if (conversionDatum.Rank != ConversionRank.Identity)
         {
             DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
             dynamicMetaObjectArray[0] = arg;
             BindingRestrictions bindingRestriction1 = target.CombineRestrictions(dynamicMetaObjectArray);
             bindingRestriction1 = bindingRestriction1.Merge(BinderUtils.GetOptionalVersionAndLanguageCheckForType(this, limitType, this._version));
             ParameterExpression parameterExpression = Expression.Parameter(typeof(bool));
             Expression[] expressionArray2 = new Expression[1];
             expressionArray2[0] = PSConvertBinder.InvokeConverter(conversionDatum, arg.Expression, limitType, flag, ExpressionCache.InvariantCulture).Cast(typeof(object));
             Expression expression3 = Expression.Call(target.Expression.Cast(typeof(object)), CachedReflectionInfo.Object_Equals, expressionArray2);
             ParameterExpression[] parameterExpressionArray = new ParameterExpression[1];
             parameterExpressionArray[0] = parameterExpression;
             Expression[] expressionArray3 = new Expression[3];
             expressionArray3[0] = Expression.Assign(parameterExpression, expression2);
             CatchBlock[] catchBlockArray = new CatchBlock[1];
             catchBlockArray[0] = Expression.Catch(typeof(InvalidCastException), Expression.Assign(parameterExpression, ExpressionCache.Constant(false)));
             expressionArray3[1] = Expression.IfThen(Expression.Not(parameterExpression), Expression.TryCatch(Expression.Assign(parameterExpression, expression3), catchBlockArray));
             expressionArray3[2] = func1(parameterExpression);
             BlockExpression blockExpression = Expression.Block(parameterExpressionArray, expressionArray3);
             return new DynamicMetaObject(blockExpression.Cast(typeof(object)), bindingRestriction1);
         }
         else
         {
             DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1];
             dynamicMetaObjectArray1[0] = arg;
             return new DynamicMetaObject(func1(expression2).Cast(typeof(object)), target.CombineRestrictions(dynamicMetaObjectArray1));
         }
     }
     else
     {
         Expression expression4 = target.Expression.Cast(typeof(string));
         if (!arg.LimitType.Equals(typeof(string)))
         {
             expression = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), arg.Expression, ExpressionCache.GetExecutionContextFromTLS);
         }
         else
         {
             expression = arg.Expression.Cast(typeof(string));
         }
         Expression expression5 = expression;
         DynamicMetaObject[] dynamicMetaObjectArray2 = new DynamicMetaObject[1];
         dynamicMetaObjectArray2[0] = arg;
         return new DynamicMetaObject(func1(Compiler.CallStringEquals(expression4, expression5, this._ignoreCase)).Cast(typeof(object)), target.CombineRestrictions(dynamicMetaObjectArray2));
     }
 }
示例#11
0
 private DynamicMetaObject BinaryComparisonCommon(DynamicMetaObject targetAsEnumerator, DynamicMetaObject target, DynamicMetaObject arg)
 {
     if (targetAsEnumerator == null || this._scalarCompare)
     {
         if (target.LimitType.IsNumeric())
         {
             DynamicMetaObject argAsNumericOrPrimitive = PSBinaryOperationBinder.GetArgAsNumericOrPrimitive(arg, target.LimitType);
             if (argAsNumericOrPrimitive == null)
             {
                 if (arg.LimitType.Equals(typeof(string)))
                 {
                     return this.BinaryNumericStringOp(target, arg);
                 }
             }
             else
             {
                 string str = null;
                 ExpressionType operation = base.Operation;
                 switch (operation)
                 {
                     case ExpressionType.Equal:
                         {
                             str = "CompareEq";
                             return this.BinaryNumericOp(str, target, argAsNumericOrPrimitive);
                         }
                     case ExpressionType.ExclusiveOr:
                     case ExpressionType.Invoke:
                     case ExpressionType.Lambda:
                     case ExpressionType.LeftShift:
                         {
                             return this.BinaryNumericOp(str, target, argAsNumericOrPrimitive);
                         }
                     case ExpressionType.GreaterThan:
                         {
                             str = "CompareGt";
                             return this.BinaryNumericOp(str, target, argAsNumericOrPrimitive);
                         }
                     case ExpressionType.GreaterThanOrEqual:
                         {
                             str = "CompareGe";
                             return this.BinaryNumericOp(str, target, argAsNumericOrPrimitive);
                         }
                     case ExpressionType.LessThan:
                         {
                             str = "CompareLt";
                             return this.BinaryNumericOp(str, target, argAsNumericOrPrimitive);
                         }
                     case ExpressionType.LessThanOrEqual:
                         {
                             str = "CompareLe";
                             return this.BinaryNumericOp(str, target, argAsNumericOrPrimitive);
                         }
                     default:
                         {
                             if (operation == ExpressionType.NotEqual)
                             {
                                 str = "CompareNe";
                                 return this.BinaryNumericOp(str, target, argAsNumericOrPrimitive);
                             }
                             else
                             {
                                 return this.BinaryNumericOp(str, target, argAsNumericOrPrimitive);
                             }
                         }
                 }
             }
         }
         return null;
     }
     else
     {
         return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.EnumerableOps_Compare, targetAsEnumerator.Expression, arg.Expression.Cast(typeof(object)), Expression.Constant(this.GetScalarCompareDelegate())), targetAsEnumerator.Restrictions.Merge(arg.PSGetTypeRestriction()));
     }
 }
示例#12
0
 private DynamicMetaObject Shift(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion, string userOp, Func<Expression, Expression, Expression> exprGenerator)
 {
     bool flag = false;
     Type type;
     Type type1;
     byte num;
     if (target.Value != null)
     {
         if (target.LimitType.Equals(typeof(string)) || arg.LimitType.Equals(typeof(string)))
         {
             return this.BinaryNumericStringOp(target, arg);
         }
         else
         {
             TypeCode typeCode = LanguagePrimitives.GetTypeCode(target.LimitType);
             if (target.LimitType.IsNumeric())
             {
                 Type type2 = typeof(int);
                 LanguagePrimitives.ConversionData conversionDatum = LanguagePrimitives.FigureConversion(arg.Value, type2, out flag);
                 if (conversionDatum.Rank != ConversionRank.None)
                 {
                     Expression expression = PSConvertBinder.InvokeConverter(conversionDatum, arg.Expression, type2, flag, ExpressionCache.InvariantCulture);
                     if (typeCode == TypeCode.Decimal || typeCode == TypeCode.Double || typeCode == TypeCode.Single)
                     {
                         if (typeCode == TypeCode.Decimal)
                         {
                             type = typeof(DecimalOps);
                         }
                         else
                         {
                             type = typeof(DoubleOps);
                         }
                         Type type3 = type;
                         if (typeCode == TypeCode.Decimal)
                         {
                             type1 = typeof(decimal);
                         }
                         else
                         {
                             type1 = typeof(double);
                         }
                         Type type4 = type1;
                         string str = userOp.Substring(3);
                         DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
                         dynamicMetaObjectArray[0] = arg;
                         return new DynamicMetaObject(Expression.Call(type3.GetMethod(str, BindingFlags.Static | BindingFlags.NonPublic), target.Expression.Cast(type4), expression), target.CombineRestrictions(dynamicMetaObjectArray));
                     }
                     else
                     {
                         Expression expression1 = target.Expression.Cast(target.LimitType);
                         Expression expression2 = expression;
                         if (typeCode < TypeCode.Int64)
                         {
                             num = 31;
                         }
                         else
                         {
                             num = 63;
                         }
                         expression = Expression.And(expression2, Expression.Constant(num, typeof(int)));
                         DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1];
                         dynamicMetaObjectArray1[0] = arg;
                         return new DynamicMetaObject(exprGenerator(expression1, expression).Cast(typeof(object)), target.CombineRestrictions(dynamicMetaObjectArray1));
                     }
                 }
                 else
                 {
                     return PSConvertBinder.ThrowNoConversion(arg, typeof(int), this, this._version, new DynamicMetaObject[0]);
                 }
             }
             else
             {
                 return PSBinaryOperationBinder.CallImplicitOp(userOp, target, arg, this.GetOperatorText(), errorSuggestion);
             }
         }
     }
     else
     {
         return new DynamicMetaObject(ExpressionCache.Constant(0).Convert(typeof(object)), target.PSGetTypeRestriction());
     }
 }
示例#13
0
 private DynamicMetaObject GetIndexArray(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion)
 {
     Array array = (Array) target.Value;
     if (array.Rank > 1)
     {
         return this.GetIndexMultiDimensionArray(target, indexes, errorSuggestion);
     }
     if (indexes.Length > 1)
     {
         if (!this._allowSlicing && (errorSuggestion == null))
         {
             return this.CannotIndexTarget(target, indexes);
         }
         return this.InvokeSlicingIndexer(target, indexes);
     }
     DynamicMetaObject obj2 = this.CheckForSlicing(target, indexes);
     if (obj2 != null)
     {
         return obj2;
     }
     Expression expression = ConvertIndex(indexes[0], typeof(int));
     if (expression == null)
     {
         return (errorSuggestion ?? PSConvertBinder.ThrowNoConversion(target, typeof(int), this, this._version, indexes));
     }
     return this.IndexWithNegativeChecks(new DynamicMetaObject(target.Expression.Cast(target.LimitType), target.PSGetTypeRestriction()), new DynamicMetaObject(expression, indexes[0].PSGetTypeRestriction()), target.LimitType.GetProperty("Length"), (t, i) => Expression.ArrayIndex(t, i).Cast(typeof(object)));
 }
示例#14
0
 internal static BindingRestrictions GetRestrictions(DynamicMetaObject target)
 {
     if (target.Value is PSObject)
     {
         return BindingRestrictions.GetTypeRestriction(target.Expression, typeof(PSObject));
     }
     return target.PSGetTypeRestriction();
 }
示例#15
0
 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());
 }
示例#16
0
 private DynamicMetaObject SetIndexArray(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
 {
     Array arrays = (Array)target.Value;
     if (arrays.Rank <= 1)
     {
         if ((int)indexes.Length <= 1)
         {
             Expression expression = PSGetIndexBinder.ConvertIndex(indexes[0], typeof(int));
             if (expression != null)
             {
                 Type elementType = target.LimitType.GetElementType();
                 Expression expression1 = PSGetIndexBinder.ConvertIndex(value, elementType);
                 if (expression1 != null)
                 {
                     PSSetIndexBinder pSSetIndexBinder = this;
                     DynamicMetaObject dynamicMetaObject = new DynamicMetaObject(target.Expression.Cast(target.LimitType), target.PSGetTypeRestriction());
                     DynamicMetaObject dynamicMetaObject1 = new DynamicMetaObject(expression, indexes[0].PSGetTypeRestriction());
                     DynamicMetaObject dynamicMetaObject2 = new DynamicMetaObject(expression1, value.PSGetTypeRestriction());
                     PropertyInfo property = target.LimitType.GetProperty("Length");
                     return pSSetIndexBinder.IndexWithNegativeChecks(dynamicMetaObject, dynamicMetaObject1, dynamicMetaObject2, property, (Expression t, Expression i, Expression v) =>
                     {
                         Expression[] expressionArray = new Expression[1];
                         expressionArray[0] = i;
                         return Expression.Assign(Expression.ArrayAccess(t, expressionArray), v);
                     }
                     );
                 }
                 else
                 {
                     DynamicMetaObject dynamicMetaObject3 = errorSuggestion;
                     DynamicMetaObject dynamicMetaObject4 = dynamicMetaObject3;
                     if (dynamicMetaObject3 == null)
                     {
                         dynamicMetaObject4 = PSConvertBinder.ThrowNoConversion(value, elementType, this, this._version, indexes.Prepend<DynamicMetaObject>(target).OfType<DynamicMetaObject>().ToArray<DynamicMetaObject>());
                     }
                     return dynamicMetaObject4;
                 }
             }
             else
             {
                 DynamicMetaObject dynamicMetaObject5 = errorSuggestion;
                 DynamicMetaObject dynamicMetaObject6 = dynamicMetaObject5;
                 if (dynamicMetaObject5 == null)
                 {
                     DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[2];
                     dynamicMetaObjectArray[0] = target;
                     dynamicMetaObjectArray[1] = value;
                     dynamicMetaObject6 = PSConvertBinder.ThrowNoConversion(indexes[0], typeof(int), this, this._version, dynamicMetaObjectArray);
                 }
                 return dynamicMetaObject6;
             }
         }
         else
         {
             DynamicMetaObject dynamicMetaObject7 = errorSuggestion;
             DynamicMetaObject dynamicMetaObject8 = dynamicMetaObject7;
             if (dynamicMetaObject7 == null)
             {
                 DynamicMetaObject dynamicMetaObject9 = target;
                 DynamicMetaObject[] dynamicMetaObjectArray1 = indexes;
                 BindingRestrictions bindingRestriction = value.PSGetTypeRestriction();
                 string str = "ArraySliceAssignmentFailed";
                 string arraySliceAssignmentFailed = ParserStrings.ArraySliceAssignmentFailed;
                 Expression[] expressionArray1 = new Expression[1];
                 Expression[] expressionArray2 = expressionArray1;
                 int num = 0;
                 MethodInfo arrayOpsIndexStringMessage = CachedReflectionInfo.ArrayOps_IndexStringMessage;
                 Type type = typeof(object);
                 DynamicMetaObject[] dynamicMetaObjectArray2 = indexes;
                 expressionArray2[num] = Expression.Call(arrayOpsIndexStringMessage, Expression.NewArrayInit(type, dynamicMetaObjectArray2.Select<DynamicMetaObject, Expression>((DynamicMetaObject i) => i.Expression.Cast(typeof(object)))));
                 dynamicMetaObject8 = dynamicMetaObject9.ThrowRuntimeError(dynamicMetaObjectArray1, bindingRestriction, str, arraySliceAssignmentFailed, expressionArray1);
             }
             return dynamicMetaObject8;
         }
     }
     else
     {
         return this.SetIndexMultiDimensionArray(target, indexes, value, errorSuggestion);
     }
 }
示例#17
0
 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());
 }
示例#18
0
 internal DynamicMetaObject Not(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
 {
     if (!target.HasValue)
     {
         return base.Defer(target, new DynamicMetaObject[0]);
     }
     return new DynamicMetaObject(Expression.Not(target.CastOrConvert(typeof(bool))).Cast(typeof(object)), target.PSGetTypeRestriction());
 }
示例#19
0
 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) }));
 }
示例#20
0
 private DynamicMetaObject InvokeIndexer(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion, string methodName)
 {
     DynamicMetaObject dynamicMetaObject;
     Func<Expression, Expression, Expression, Expression> func = null;
     MethodInfo methodInfo = PSInvokeMemberBinder.FindBestMethod(target, indexes.Append<DynamicMetaObject>(value), string.Concat("set_", methodName), false, this._constraints);
     if (methodInfo != null)
     {
         ParameterInfo[] parameters = methodInfo.GetParameters();
         if ((int)parameters.Length == (int)indexes.Length + 1)
         {
             Expression[] expressionArray = new Expression[(int)parameters.Length];
             int num = 0;
             while (num < (int)parameters.Length)
             {
                 Type parameterType = parameters[num].ParameterType;
                 Expression[] expressionArray1 = expressionArray;
                 int num1 = num;
                 if (num == (int)parameters.Length - 1)
                 {
                     dynamicMetaObject = value;
                 }
                 else
                 {
                     dynamicMetaObject = indexes[num];
                 }
                 expressionArray1[num1] = PSGetIndexBinder.ConvertIndex(dynamicMetaObject, parameterType);
                 if (expressionArray[num] != null)
                 {
                     num++;
                 }
                 else
                 {
                     DynamicMetaObject dynamicMetaObject1 = errorSuggestion;
                     DynamicMetaObject dynamicMetaObject2 = dynamicMetaObject1;
                     if (dynamicMetaObject1 == null)
                     {
                         dynamicMetaObject2 = PSConvertBinder.ThrowNoConversion(target, parameterType, this, this._version, indexes.Append<DynamicMetaObject>(value).ToArray<DynamicMetaObject>());
                     }
                     return dynamicMetaObject2;
                 }
             }
             if ((int)parameters.Length == 2 && parameters[0].ParameterType.Equals(typeof(int)) && target.Value as IDictionary == null)
             {
                 PropertyInfo property = target.LimitType.GetProperty("Length");
                 PropertyInfo propertyInfo = property;
                 if (property == null)
                 {
                     propertyInfo = target.LimitType.GetProperty("Count");
                 }
                 PropertyInfo propertyInfo1 = propertyInfo;
                 if (propertyInfo1 != null)
                 {
                     PSSetIndexBinder pSSetIndexBinder = this;
                     DynamicMetaObject dynamicMetaObject3 = new DynamicMetaObject(target.Expression.Cast(target.LimitType), target.PSGetTypeRestriction());
                     DynamicMetaObject dynamicMetaObject4 = new DynamicMetaObject(expressionArray[0], indexes[0].PSGetTypeRestriction());
                     DynamicMetaObject dynamicMetaObject5 = new DynamicMetaObject(expressionArray[1], value.PSGetTypeRestriction());
                     PropertyInfo propertyInfo2 = propertyInfo1;
                     if (func == null)
                     {
                         func = (Expression t, Expression i, Expression v) => Expression.Call(t, methodInfo, i, v);
                     }
                     return pSSetIndexBinder.IndexWithNegativeChecks(dynamicMetaObject3, dynamicMetaObject4, dynamicMetaObject5, propertyInfo2, func);
                 }
             }
             BindingRestrictions bindingRestriction = target.CombineRestrictions(indexes).Merge(value.PSGetTypeRestriction());
             bindingRestriction = bindingRestriction.Merge(BinderUtils.GetVersionCheck(this, this._version));
             bindingRestriction = bindingRestriction.Merge(BinderUtils.GetLanguageModeCheckIfHasEverUsedConstrainedLanguage());
             Expression expression = expressionArray[(int)expressionArray.Length - 1];
             ParameterExpression parameterExpression = Expression.Parameter(expression.Type, "value");
             expressionArray[(int)expressionArray.Length - 1] = parameterExpression;
             ParameterExpression[] parameterExpressionArray = new ParameterExpression[1];
             parameterExpressionArray[0] = parameterExpression;
             Expression[] expressionArray2 = new Expression[3];
             expressionArray2[0] = Expression.Assign(parameterExpression, expression);
             expressionArray2[1] = Expression.Call(target.Expression.Cast(target.LimitType), methodInfo, expressionArray);
             expressionArray2[2] = parameterExpression.Cast(typeof(object));
             return new DynamicMetaObject(Expression.Block(parameterExpressionArray, expressionArray2), bindingRestriction);
         }
         else
         {
             DynamicMetaObject dynamicMetaObject6 = errorSuggestion;
             DynamicMetaObject dynamicMetaObject7 = dynamicMetaObject6;
             if (dynamicMetaObject6 == null)
             {
                 dynamicMetaObject7 = this.CannotIndexTarget(target, indexes, value);
             }
             return dynamicMetaObject7;
         }
     }
     else
     {
         DynamicMetaObject dynamicMetaObject8 = errorSuggestion;
         DynamicMetaObject dynamicMetaObject9 = dynamicMetaObject8;
         if (dynamicMetaObject8 == null)
         {
             dynamicMetaObject9 = this.CannotIndexTarget(target, indexes, value);
         }
         return dynamicMetaObject9;
     }
 }
示例#21
0
 private static DynamicMetaObject FigureSignedUnsignedInt(DynamicMetaObject obj, TypeCode typeCode, out Type opImplType, out Type argType)
 {
     if (!PSBinaryOperationBinder.IsValueNegative(obj.Value, typeCode))
     {
         opImplType = null;
         argType = null;
         return new DynamicMetaObject(obj.Expression, obj.PSGetTypeRestriction().Merge(BindingRestrictions.GetExpressionRestriction(Expression.GreaterThanOrEqual(obj.Expression.Cast(obj.LimitType), PSBinaryOperationBinder.TypedZero(typeCode)))), obj.Value);
     }
     else
     {
         opImplType = typeof(DoubleOps);
         argType = typeof(double);
         return new DynamicMetaObject(obj.Expression, obj.PSGetTypeRestriction().Merge(BindingRestrictions.GetExpressionRestriction(Expression.LessThan(obj.Expression.Cast(obj.LimitType), PSBinaryOperationBinder.TypedZero(typeCode)))), obj.Value);
     }
 }
示例#22
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);
         }
     }
 }
示例#23
0
 private static DynamicMetaObject GetArgAsNumericOrPrimitive(DynamicMetaObject arg, Type targetType)
 {
     bool flag = false;
     if (arg.Value != null)
     {
         bool flag1 = false;
         if (arg.LimitType.IsNumericOrPrimitive())
         {
             if (!targetType.Equals(typeof(decimal)) || !arg.LimitType.Equals(typeof(bool)))
             {
                 return arg;
             }
             else
             {
                 flag1 = true;
             }
         }
         LanguagePrimitives.ConversionData conversionDatum = LanguagePrimitives.FigureConversion(arg.Value, targetType, out flag);
         if (conversionDatum.Rank == ConversionRank.ImplicitCast || flag1 || arg.LimitType.IsEnum)
         {
             return new DynamicMetaObject(PSConvertBinder.InvokeConverter(conversionDatum, arg.Expression, targetType, flag, ExpressionCache.InvariantCulture), arg.PSGetTypeRestriction());
         }
         else
         {
             return null;
         }
     }
     else
     {
         return new DynamicMetaObject(ExpressionCache.Constant(0), arg.PSGetTypeRestriction(), (object)0);
     }
 }
示例#24
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);
 }
示例#25
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;
     }
 }
示例#26
0
 private DynamicMetaObject InvokeIndexer(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject errorSuggestion, string methodName)
 {
     Func<Expression, Expression, Expression> generateIndexOperation = null;
     MethodInfo getter = PSInvokeMemberBinder.FindBestMethod(target, indexes, "get_" + methodName, false, this._constraints);
     if (getter == null)
     {
         return (this.CheckForSlicing(target, indexes) ?? (errorSuggestion ?? this.CannotIndexTarget(target, indexes)));
     }
     ParameterInfo[] parameters = getter.GetParameters();
     if (parameters.Length != indexes.Length)
     {
         if ((parameters.Length == 1) && this._allowSlicing)
         {
             return this.InvokeSlicingIndexer(target, indexes);
         }
         return (errorSuggestion ?? this.CannotIndexTarget(target, indexes));
     }
     if (parameters.Length == 1)
     {
         DynamicMetaObject obj2 = this.CheckForSlicing(target, indexes);
         if (obj2 != null)
         {
             return obj2;
         }
     }
     Expression[] arguments = new Expression[parameters.Length];
     for (int j = 0; j < parameters.Length; j++)
     {
         Type parameterType = parameters[j].ParameterType;
         arguments[j] = ConvertIndex(indexes[j], parameterType);
         if (arguments[j] == null)
         {
             return (errorSuggestion ?? PSConvertBinder.ThrowNoConversion(target, parameterType, this, this._version, indexes));
         }
     }
     if (((parameters.Length == 1) && parameters[0].ParameterType.Equals(typeof(int))) && CanIndexFromEndWithNegativeIndex(target))
     {
         PropertyInfo lengthProperty = target.LimitType.GetProperty("Count") ?? target.LimitType.GetProperty("Length");
         if (lengthProperty != null)
         {
             if (generateIndexOperation == null)
             {
                 generateIndexOperation = (t, i) => Expression.Call(t, getter, new Expression[] { i }).Cast(typeof(object));
             }
             return this.IndexWithNegativeChecks(new DynamicMetaObject(target.Expression.Cast(target.LimitType), target.PSGetTypeRestriction()), new DynamicMetaObject(arguments[0], indexes[0].PSGetTypeRestriction()), lengthProperty, generateIndexOperation);
         }
     }
     return new DynamicMetaObject(this.SafeIndexResult(Expression.Call(target.Expression.Cast(target.LimitType), getter, arguments)), target.CombineRestrictions(indexes).Merge(BinderUtils.GetVersionCheck(this, this._version)).Merge(BinderUtils.GetLanguageModeCheckIfHasEverUsedConstrainedLanguage()));
 }
示例#27
0
 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);
     }
 }