Пример #1
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;
     }
 }