private DynamicMetaObject CheckForSlicing(DynamicMetaObject target, DynamicMetaObject[] indexes) { if (this._allowSlicing) { if (indexes.Length > 1) { PSGetIndexBinder nonSlicingBinder = Get(1, this._constraints, false); return new DynamicMetaObject(Expression.NewArrayInit(typeof(object), (IEnumerable<Expression>) (from i in indexes select Expression.Dynamic(nonSlicingBinder, typeof(object), target.Expression, i.Expression))), target.CombineRestrictions(indexes)); } DynamicMetaObject obj2 = PSEnumerableBinder.IsEnumerable(indexes[0]); if (obj2 != null) { return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.EnumerableOps_SlicingIndex, target.Expression.Cast(typeof(object)), obj2.Expression.Cast(typeof(IEnumerator)), Expression.Constant(this.GetNonSlicingIndexer())), target.CombineRestrictions(new DynamicMetaObject[] { obj2 })); } } return null; }
private static DynamicMetaObject CallImplicitOp(string methodName, DynamicMetaObject target, DynamicMetaObject arg, string errorOperator, DynamicMetaObject errorSuggestion) { if (errorSuggestion == null || target.Value as DynamicObject == null) { DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ParserOps_ImplicitOp, target.Expression.Cast(typeof(object)), arg.Expression.Cast(typeof(object)), Expression.Constant(methodName), ExpressionCache.NullExtent, Expression.Constant(errorOperator)), target.CombineRestrictions(dynamicMetaObjectArray)); } else { return errorSuggestion; } }
private DynamicMetaObject BinaryNumericStringOp(DynamicMetaObject target, DynamicMetaObject arg) { Expression number; Expression boxedFalse; List<ParameterExpression> parameterExpressions = new List<ParameterExpression>(); List<Expression> expressions = new List<Expression>(); Expression expression = target.Expression; if (target.LimitType.Equals(typeof(string))) { expression = PSBinaryOperationBinder.ConvertStringToNumber(target.Expression, arg.LimitType); } if (arg.LimitType.Equals(typeof(string))) { number = PSBinaryOperationBinder.ConvertStringToNumber(arg.Expression, target.LimitType); } else { number = arg.Expression; } Expression expression1 = number; expressions.Add(Expression.Dynamic(PSBinaryOperationBinder.Get(base.Operation, true, false), typeof(object), expression, expression1)); Expression expression2 = Expression.Block(parameterExpressions, expressions); if (base.Operation == ExpressionType.Equal || base.Operation == ExpressionType.NotEqual) { Expression expression3 = expression2; CatchBlock[] catchBlockArray = new CatchBlock[1]; CatchBlock[] catchBlockArray1 = catchBlockArray; int num = 0; Type type = typeof(InvalidCastException); if (base.Operation == ExpressionType.Equal) { boxedFalse = ExpressionCache.BoxedFalse; } else { boxedFalse = ExpressionCache.BoxedTrue; } catchBlockArray1[num] = Expression.Catch(type, boxedFalse); expression2 = Expression.TryCatch(expression3, catchBlockArray); } DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; return new DynamicMetaObject(expression2, target.CombineRestrictions(dynamicMetaObjectArray)); }
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; } }
private DynamicMetaObject CannotIndexTarget(DynamicMetaObject target, DynamicMetaObject[] indexes) { return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_GetNonIndexable, target.Expression.Cast(typeof(object)), Expression.NewArrayInit(typeof(object), (IEnumerable<Expression>) (from d in indexes select d.Expression.Cast(typeof(object))))), target.CombineRestrictions(indexes).Merge(BinderUtils.GetVersionCheck(this, this._version)).Merge(BinderUtils.GetLanguageModeCheckIfHasEverUsedConstrainedLanguage())); }
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())); }
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)); }
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); }
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()); } }
private DynamicMetaObject BinaryBitwiseOp(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion, Func<Expression, Expression, Expression> exprGenerator, string implicitMethodName, string errorOperatorName, string methodName) { Type bitwiseOpType; Type type; Type type1; DynamicMetaObject argAsNumericOrPrimitive; DynamicMetaObject dynamicMetaObject; Type enumUnderlyingType; Type limitType; TypeCode typeCode; TypeCode typeCode1; if (target.Value != null || arg.Value != null) { if (target.LimitType.IsEnum) { enumUnderlyingType = target.LimitType.GetEnumUnderlyingType(); } else { enumUnderlyingType = target.LimitType; } Type type2 = enumUnderlyingType; if (arg.LimitType.IsEnum) { limitType = arg.LimitType.GetEnumUnderlyingType(); } else { limitType = arg.LimitType; } Type type3 = limitType; if (type2.IsNumericOrPrimitive() || type3.IsNumericOrPrimitive()) { TypeCode typeCode2 = LanguagePrimitives.GetTypeCode(type2); TypeCode typeCode3 = LanguagePrimitives.GetTypeCode(type3); if (typeCode2 >= typeCode3) { typeCode = typeCode2; } else { typeCode = typeCode3; } TypeCode typeCode4 = typeCode; if (type2.IsNumericOrPrimitive()) { if (type3.IsNumericOrPrimitive()) { argAsNumericOrPrimitive = target; dynamicMetaObject = arg; } else { bitwiseOpType = PSBinaryOperationBinder.GetBitwiseOpType(typeCode2); argAsNumericOrPrimitive = target; dynamicMetaObject = PSBinaryOperationBinder.GetArgAsNumericOrPrimitive(arg, bitwiseOpType); } } else { bitwiseOpType = PSBinaryOperationBinder.GetBitwiseOpType(typeCode3); argAsNumericOrPrimitive = PSBinaryOperationBinder.GetArgAsNumericOrPrimitive(target, bitwiseOpType); dynamicMetaObject = arg; } if (typeCode4 != TypeCode.Decimal) { if (typeCode4 == TypeCode.Double || typeCode4 == TypeCode.Single) { type = typeof(DoubleOps); type1 = typeof(double); DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = dynamicMetaObject; return new DynamicMetaObject(Expression.Call(type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic), argAsNumericOrPrimitive.Expression.Cast(argAsNumericOrPrimitive.LimitType).Convert(type1), dynamicMetaObject.Expression.Cast(dynamicMetaObject.LimitType).Convert(type1)), argAsNumericOrPrimitive.CombineRestrictions(dynamicMetaObjectArray)); } else { if (typeCode2 >= typeCode3) { typeCode1 = typeCode2; } else { typeCode1 = typeCode3; } bitwiseOpType = PSBinaryOperationBinder.GetBitwiseOpType(typeCode1); if (argAsNumericOrPrimitive != null && dynamicMetaObject != null) { DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1]; dynamicMetaObjectArray1[0] = dynamicMetaObject; return new DynamicMetaObject(exprGenerator(argAsNumericOrPrimitive.Expression.Cast(target.LimitType).Cast(bitwiseOpType), dynamicMetaObject.Expression.Cast(dynamicMetaObject.LimitType).Cast(bitwiseOpType)).Cast(typeof(object)), argAsNumericOrPrimitive.CombineRestrictions(dynamicMetaObjectArray1)); } } } else { type = typeof(DecimalOps); type1 = typeof(decimal); DynamicMetaObject[] dynamicMetaObjectArray2 = new DynamicMetaObject[1]; dynamicMetaObjectArray2[0] = dynamicMetaObject; return new DynamicMetaObject(Expression.Call(type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic), argAsNumericOrPrimitive.Expression.Cast(argAsNumericOrPrimitive.LimitType).Convert(type1), dynamicMetaObject.Expression.Cast(dynamicMetaObject.LimitType).Convert(type1)), argAsNumericOrPrimitive.CombineRestrictions(dynamicMetaObjectArray2)); } } if (target.LimitType.Equals(typeof(string)) || arg.LimitType.Equals(typeof(string))) { return this.BinaryNumericStringOp(target, arg); } else { return PSBinaryOperationBinder.CallImplicitOp(implicitMethodName, target, arg, errorOperatorName, errorSuggestion); } } else { DynamicMetaObject[] dynamicMetaObjectArray3 = new DynamicMetaObject[1]; dynamicMetaObjectArray3[0] = arg; return new DynamicMetaObject(ExpressionCache.Constant(0).Cast(typeof(object)), target.CombineRestrictions(dynamicMetaObjectArray3)); } }
public override DynamicMetaObject FallbackBinaryOperation(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion) { object[] objArray; DynamicMetaObject[] dynamicMetaObjectArray; DynamicMetaObject dynamicMetaObject; DynamicMetaObject dynamicMetaObject1; if (!target.HasValue || !arg.HasValue) { DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1]; dynamicMetaObjectArray1[0] = arg; return base.Defer(target, dynamicMetaObjectArray1).WriteToDebugLog(this); } else { if ((target.Value as PSObject == null || PSObject.Base(target.Value) == target.Value) && (arg.Value as PSObject == null || PSObject.Base(arg.Value) == arg.Value) || base.Operation == ExpressionType.Add && PSEnumerableBinder.IsEnumerable(target) != null) { ExpressionType operation = base.Operation; if (operation > ExpressionType.Multiply) { if (operation == ExpressionType.NotEqual) { return this.CompareNE(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.Or) { return this.BinaryBitwiseOr(target, arg, errorSuggestion).WriteToDebugLog(this); } if (operation == ExpressionType.RightShift) { return this.RightShift(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.Subtract) { return this.BinarySub(target, arg, errorSuggestion).WriteToDebugLog(this); } } else { if (operation == ExpressionType.Add) { return this.BinaryAdd(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.AddChecked) { dynamicMetaObject = errorSuggestion; dynamicMetaObject1 = dynamicMetaObject; if (dynamicMetaObject == null) { objArray = new object[1]; objArray[0] = "Unimplemented operaton"; dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; dynamicMetaObject1 = new DynamicMetaObject(Compiler.CreateThrow(typeof(object), typeof(PSNotImplementedException), objArray), target.CombineRestrictions(dynamicMetaObjectArray)); } return dynamicMetaObject1.WriteToDebugLog(this); } else if (operation == ExpressionType.And) { return this.BinaryBitwiseAnd(target, arg, errorSuggestion).WriteToDebugLog(this); } if (operation == ExpressionType.Divide) { return this.BinaryDivide(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.Equal) { return this.CompareEQ(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.ExclusiveOr) { return this.BinaryBitwiseXor(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.GreaterThan) { return this.CompareGT(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.GreaterThanOrEqual) { return this.CompareGE(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.Invoke || operation == ExpressionType.Lambda || operation == ExpressionType.ListInit || operation == ExpressionType.MemberAccess || operation == ExpressionType.MemberInit) { dynamicMetaObject = errorSuggestion; dynamicMetaObject1 = dynamicMetaObject; if (dynamicMetaObject == null) { objArray = new object[1]; objArray[0] = "Unimplemented operaton"; dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; dynamicMetaObject1 = new DynamicMetaObject(Compiler.CreateThrow(typeof(object), typeof(PSNotImplementedException), objArray), target.CombineRestrictions(dynamicMetaObjectArray)); } return dynamicMetaObject1.WriteToDebugLog(this); } else if (operation == ExpressionType.LeftShift) { return this.LeftShift(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.LessThan) { return this.CompareLT(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.LessThanOrEqual) { return this.CompareLE(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.Modulo) { return this.BinaryRemainder(target, arg, errorSuggestion).WriteToDebugLog(this); } else if (operation == ExpressionType.Multiply) { return this.BinaryMultiply(target, arg, errorSuggestion).WriteToDebugLog(this); } } dynamicMetaObject = errorSuggestion; dynamicMetaObject1 = dynamicMetaObject; if (dynamicMetaObject == null) { objArray = new object[1]; objArray[0] = "Unimplemented operaton"; dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; dynamicMetaObject1 = new DynamicMetaObject(Compiler.CreateThrow(typeof(object), typeof(PSNotImplementedException), objArray), target.CombineRestrictions(dynamicMetaObjectArray)); } return dynamicMetaObject1.WriteToDebugLog(this); } else { DynamicMetaObject[] dynamicMetaObjectArray2 = new DynamicMetaObject[2]; dynamicMetaObjectArray2[0] = target; dynamicMetaObjectArray2[1] = arg; return this.DeferForPSObject(dynamicMetaObjectArray2).WriteToDebugLog(this); } } }
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)); }
internal static DynamicMetaObject ThrowNoConversion(DynamicMetaObject target, Type toType, DynamicMetaObjectBinder binder, int currentVersion, params DynamicMetaObject[] args) { Expression expression = Expression.Call(CachedReflectionInfo.LanguagePrimitives_ThrowInvalidCastException, target.Expression.Cast(typeof(object)), Expression.Constant(toType)); if (!binder.ReturnType.Equals(typeof(void))) { expression = Expression.Block(expression, Expression.Default(binder.ReturnType)); } return new DynamicMetaObject(expression, target.CombineRestrictions(args).Merge(BinderUtils.GetOptionalVersionAndLanguageCheckForType(binder, toType, currentVersion))); }
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; } }
private DynamicMetaObject CompareEQ(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion) { Expression boxedTrue; if (target.Value != null) { DynamicMetaObject dynamicMetaObject = PSEnumerableBinder.IsEnumerable(target); if (dynamicMetaObject != null || arg.Value != null) { DynamicMetaObject dynamicMetaObject1 = this.BinaryComparisonCommon(dynamicMetaObject, target, arg); DynamicMetaObject dynamicMetaObject2 = dynamicMetaObject1; if (dynamicMetaObject1 == null) { dynamicMetaObject2 = this.BinaryEqualityComparison(target, arg); } return dynamicMetaObject2; } else { DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; return new DynamicMetaObject(ExpressionCache.BoxedFalse, target.CombineRestrictions(dynamicMetaObjectArray)); } } else { if (arg.Value == null) { boxedTrue = ExpressionCache.BoxedTrue; } else { boxedTrue = ExpressionCache.BoxedFalse; } DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1]; dynamicMetaObjectArray1[0] = arg; return new DynamicMetaObject(boxedTrue, target.CombineRestrictions(dynamicMetaObjectArray1)); } }
private DynamicMetaObject CompareLE(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion) { Expression boxedFalse; DynamicMetaObject dynamicMetaObject = PSEnumerableBinder.IsEnumerable(target); if (dynamicMetaObject != null || target.Value != null && arg.Value != null) { DynamicMetaObject dynamicMetaObject1 = this.BinaryComparisonCommon(dynamicMetaObject, target, arg); DynamicMetaObject dynamicMetaObject2 = dynamicMetaObject1; if (dynamicMetaObject1 == null) { PSBinaryOperationBinder pSBinaryOperationBinder = this; DynamicMetaObject dynamicMetaObject3 = target; DynamicMetaObject dynamicMetaObject4 = arg; dynamicMetaObject2 = pSBinaryOperationBinder.BinaryComparision(dynamicMetaObject3, dynamicMetaObject4, (Expression e) => Expression.LessThanOrEqual(e, ExpressionCache.Constant(0))); } return dynamicMetaObject2; } else { if (target.LimitType.IsNumeric()) { boxedFalse = PSBinaryOperationBinder.CompareWithZero(target, new Func<Expression, Expression, Expression>(Expression.LessThan)); } else { if (arg.LimitType.IsNumeric()) { boxedFalse = PSBinaryOperationBinder.CompareWithZero(arg, new Func<Expression, Expression, Expression>(Expression.GreaterThanOrEqual)); } else { if (target.Value != null) { boxedFalse = ExpressionCache.BoxedFalse; } else { boxedFalse = ExpressionCache.BoxedTrue; } } } Expression expression = boxedFalse; DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; return new DynamicMetaObject(expression, target.CombineRestrictions(dynamicMetaObjectArray)); } }
private DynamicMetaObject BinaryComparision(DynamicMetaObject target, DynamicMetaObject arg, Func<Expression, Expression> toResult) { bool flag = false; Expression expression; Expression boxedTrue; Expression expression1; Expression stringComparisonInvariantCultureIgnoreCase; if (!target.LimitType.Equals(typeof(string))) { Type limitType = target.LimitType; LanguagePrimitives.ConversionData conversionDatum = LanguagePrimitives.FigureConversion(arg.Value, limitType, out flag); DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; BindingRestrictions bindingRestriction = target.CombineRestrictions(dynamicMetaObjectArray); bindingRestriction = bindingRestriction.Merge(BinderUtils.GetOptionalVersionAndLanguageCheckForType(this, limitType, this._version)); if (conversionDatum.Rank != ConversionRank.Identity) { ParameterExpression parameterExpression = Expression.Parameter(typeof(InvalidCastException)); CatchBlock[] catchBlockArray = new CatchBlock[1]; Expression[] expressionArray = new Expression[3]; expressionArray[0] = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), target.Expression, ExpressionCache.GetExecutionContextFromTLS); expressionArray[1] = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), arg.Expression, ExpressionCache.GetExecutionContextFromTLS); expressionArray[2] = Expression.Property(parameterExpression, CachedReflectionInfo.Exception_Message); catchBlockArray[0] = Expression.Catch(parameterExpression, Compiler.ThrowRuntimeErrorWithInnerException("ComparisonFailure", Expression.Constant(ExtendedTypeSystem.ComparisonFailure), parameterExpression, limitType, expressionArray)); expression = Expression.TryCatch(PSConvertBinder.InvokeConverter(conversionDatum, arg.Expression, limitType, flag, ExpressionCache.InvariantCulture), catchBlockArray); } else { expression = arg.Expression; } if (target.LimitType.Equals(arg.LimitType)) { Type[] interfaces = target.Value.GetType().GetInterfaces(); int num = 0; while (num < (int)interfaces.Length) { Type type = interfaces[num]; if (!type.IsGenericType || !(type.GetGenericTypeDefinition() == typeof(IComparable<>))) { num++; } else { Expression[] expressionArray1 = new Expression[1]; expressionArray1[0] = expression.Cast(arg.LimitType); DynamicMetaObject dynamicMetaObject = new DynamicMetaObject(toResult(Expression.Call(Expression.Convert(target.Expression, type), type.GetMethod("CompareTo"), expressionArray1)).Cast(typeof(object)), bindingRestriction); return dynamicMetaObject; } } } if (target.Value as IComparable == null) { Expression[] expression2 = new Expression[1]; expression2[0] = target.Expression; Expression expression3 = Compiler.ThrowRuntimeError("NotIcomparable", ExtendedTypeSystem.NotIcomparable, this.ReturnType, expression2); Expression[] expressionArray2 = new Expression[1]; expressionArray2[0] = arg.Expression.Cast(typeof(object)); MethodCallExpression methodCallExpression = Expression.Call(target.Expression.Cast(typeof(object)), CachedReflectionInfo.Object_Equals, expressionArray2); if (base.Operation == ExpressionType.GreaterThanOrEqual || base.Operation == ExpressionType.LessThanOrEqual) { boxedTrue = ExpressionCache.BoxedTrue; } else { boxedTrue = ExpressionCache.BoxedFalse; } return new DynamicMetaObject(Expression.Condition(methodCallExpression, boxedTrue, expression3), bindingRestriction); } else { Expression[] expressionArray3 = new Expression[1]; expressionArray3[0] = expression.Cast(typeof(object)); return new DynamicMetaObject(toResult(Expression.Call(target.Expression.Cast(typeof(IComparable)), CachedReflectionInfo.IComparable_CompareTo, expressionArray3)).Cast(typeof(object)), bindingRestriction); } } else { Expression expression4 = target.Expression.Cast(typeof(string)); if (!arg.LimitType.Equals(typeof(string))) { expression1 = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), arg.Expression, ExpressionCache.GetExecutionContextFromTLS); } else { expression1 = arg.Expression.Cast(typeof(string)); } Expression expression5 = expression1; MethodInfo stringCompare = CachedReflectionInfo.String_Compare; Expression expression6 = expression4; Expression expression7 = expression5; if (this._ignoreCase) { stringComparisonInvariantCultureIgnoreCase = ExpressionCache.StringComparisonInvariantCultureIgnoreCase; } else { stringComparisonInvariantCultureIgnoreCase = ExpressionCache.StringComparisonInvariantCulture; } MethodCallExpression methodCallExpression1 = Expression.Call(stringCompare, expression6, expression7, stringComparisonInvariantCultureIgnoreCase); DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1]; dynamicMetaObjectArray1[0] = arg; return new DynamicMetaObject(toResult(methodCallExpression1).Cast(typeof(object)), target.CombineRestrictions(dynamicMetaObjectArray1)); } }
private DynamicMetaObject GetIndexDictionary(DynamicMetaObject target, DynamicMetaObject[] indexes, Type idictionary) { bool flag; if (indexes.Length > 1) { return null; } MethodInfo method = idictionary.GetMethod("TryGetValue"); ParameterInfo[] parameters = method.GetParameters(); Type parameterType = parameters[0].ParameterType; LanguagePrimitives.ConversionData conversion = LanguagePrimitives.FigureConversion(indexes[0].Value, parameterType, out flag); if (conversion.Rank == ConversionRank.None) { return null; } if (indexes[0].LimitType.IsArray && !parameterType.IsArray) { return null; } BindingRestrictions restrictions = target.CombineRestrictions(indexes).Merge(BinderUtils.GetOptionalVersionAndLanguageCheckForType(this, parameterType, this._version)); Expression expression = PSConvertBinder.InvokeConverter(conversion, indexes[0].Expression, parameterType, flag, ExpressionCache.InvariantCulture); ParameterExpression expression2 = Expression.Parameter(parameters[1].ParameterType.GetElementType(), "outParam"); return new DynamicMetaObject(Expression.Block(new ParameterExpression[] { expression2 }, new Expression[] { Expression.Condition(Expression.Call(target.Expression.Cast(idictionary), method, expression, expression2), expression2.Cast(typeof(object)), this.GetNullResult()) }), restrictions); }
private DynamicMetaObject BinaryAdd(DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion) { Expression expression; if (target.Value != null) { if (target.LimitType.IsNumericOrPrimitive() && !target.LimitType.Equals(typeof(char))) { 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("Add", target, argAsNumericOrPrimitive); } } Expression expression1 = null; if (target.LimitType != typeof(string)) { if (target.LimitType == typeof(char)) { Expression[] expressionArray = new Expression[2]; expressionArray[0] = target.Expression.Cast(typeof(char)); expressionArray[1] = ExpressionCache.Constant(1); expression1 = Expression.New(CachedReflectionInfo.String_ctor_char_int, expressionArray); } } else { expression1 = target.Expression.Cast(typeof(string)); } if (expression1 == null) { DynamicMetaObject dynamicMetaObject = PSEnumerableBinder.IsEnumerable(target); if (dynamicMetaObject == null) { if (target.Value as IDictionary == null) { return PSBinaryOperationBinder.CallImplicitOp("op_Addition", target, arg, "+", errorSuggestion); } else { if (arg.Value as IDictionary == null) { DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; return target.ThrowRuntimeError(dynamicMetaObjectArray, BindingRestrictions.Empty, "AddHashTableToNonHashTable", ParserStrings.AddHashTableToNonHashTable, new Expression[0]); } else { DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1]; dynamicMetaObjectArray1[0] = arg; return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.HashtableOps_Add, target.Expression.Cast(typeof(IDictionary)), arg.Expression.Cast(typeof(IDictionary))), target.CombineRestrictions(dynamicMetaObjectArray1)); } } } else { DynamicMetaObject dynamicMetaObject1 = PSEnumerableBinder.IsEnumerable(arg); if (dynamicMetaObject1 == null) { expression = Expression.Call(CachedReflectionInfo.EnumerableOps_AddObject, ExpressionCache.GetExecutionContextFromTLS, dynamicMetaObject.Expression.Cast(typeof(IEnumerator)), arg.Expression.Cast(typeof(object))); } else { expression = Expression.Call(CachedReflectionInfo.EnumerableOps_AddEnumerable, ExpressionCache.GetExecutionContextFromTLS, dynamicMetaObject.Expression.Cast(typeof(IEnumerator)), dynamicMetaObject1.Expression.Cast(typeof(IEnumerator))); } DynamicMetaObject[] dynamicMetaObjectArray2 = new DynamicMetaObject[1]; dynamicMetaObjectArray2[0] = arg; return new DynamicMetaObject(expression, target.CombineRestrictions(dynamicMetaObjectArray2)); } } else { DynamicMetaObject[] dynamicMetaObjectArray3 = new DynamicMetaObject[1]; dynamicMetaObjectArray3[0] = arg; return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.String_Concat_String, expression1, PSToStringBinder.InvokeToString(ExpressionCache.GetExecutionContextFromTLS, arg.Expression)), target.CombineRestrictions(dynamicMetaObjectArray3)); } } else { DynamicMetaObject[] dynamicMetaObjectArray4 = new DynamicMetaObject[1]; dynamicMetaObjectArray4[0] = arg; return new DynamicMetaObject(arg.Expression.Cast(typeof(object)), target.CombineRestrictions(dynamicMetaObjectArray4)); } }
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 })); }
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)); } }
private DynamicMetaObject InvokeSlicingIndexer(DynamicMetaObject target, DynamicMetaObject[] indexes) { return new DynamicMetaObject(Expression.Call(CachedReflectionInfo.ArrayOps_SlicingIndex, target.Expression.Cast(typeof(object)), Expression.NewArrayInit(typeof(object), (IEnumerable<Expression>) (from dmo in indexes select dmo.Expression.Cast(typeof(object)))), Expression.Constant(this.GetNonSlicingIndexer())), target.CombineRestrictions(indexes)); }
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()); } }
private DynamicMetaObject BinaryNumericOp(string methodName, DynamicMetaObject target, DynamicMetaObject arg) { TypeCode typeCode; Expression boxedFalse; Type type = null; Type type1 = null; TypeCode typeCode1 = LanguagePrimitives.GetTypeCode(target.LimitType); TypeCode typeCode2 = LanguagePrimitives.GetTypeCode(arg.LimitType); if (typeCode1 >= typeCode2) { typeCode = typeCode1; } else { typeCode = typeCode2; } TypeCode typeCode3 = typeCode; if (typeCode3 > TypeCode.Int32) { if (typeCode3 > TypeCode.UInt32) { if (typeCode3 > TypeCode.Int64) { if (typeCode3 > TypeCode.UInt64) { if (typeCode3 != TypeCode.Decimal) { type = typeof(DoubleOps); type1 = typeof(double); } else { if (methodName.StartsWith("Compare", StringComparison.Ordinal)) { if (!LanguagePrimitives.IsFloating(typeCode1)) { if (LanguagePrimitives.IsFloating(typeCode2)) { DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1]; dynamicMetaObjectArray[0] = arg; return new DynamicMetaObject(Expression.Call(typeof(DecimalOps).GetMethod(string.Concat(methodName, "2"), BindingFlags.Static | BindingFlags.NonPublic), target.Expression.Cast(target.LimitType).Cast(typeof(decimal)), arg.Expression.Cast(arg.LimitType).Cast(typeof(double))), target.CombineRestrictions(dynamicMetaObjectArray)); } } else { DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1]; dynamicMetaObjectArray1[0] = arg; return new DynamicMetaObject(Expression.Call(typeof(DecimalOps).GetMethod(string.Concat(methodName, "1"), BindingFlags.Static | BindingFlags.NonPublic), target.Expression.Cast(target.LimitType).Cast(typeof(double)), arg.Expression.Cast(arg.LimitType).Cast(typeof(decimal))), target.CombineRestrictions(dynamicMetaObjectArray1)); } } type = typeof(DecimalOps); type1 = typeof(decimal); } } else { if (!LanguagePrimitives.IsSignedInteger(typeCode1)) { if (LanguagePrimitives.IsSignedInteger(typeCode2)) { arg = PSBinaryOperationBinder.FigureSignedUnsignedInt(arg, typeCode2, out type, out type1); } } else { target = PSBinaryOperationBinder.FigureSignedUnsignedInt(target, typeCode1, out type, out type1); } if (type == null) { type = typeof(ULongOps); type1 = typeof(ulong); } } } else { type = typeof(LongOps); type1 = typeof(long); } } else { if (!LanguagePrimitives.IsSignedInteger(typeCode1)) { if (LanguagePrimitives.IsSignedInteger(typeCode2)) { arg = PSBinaryOperationBinder.FigureSignedUnsignedInt(arg, typeCode2, out type, out type1); } } else { target = PSBinaryOperationBinder.FigureSignedUnsignedInt(target, typeCode1, out type, out type1); } if (type == null) { type = typeof(UIntOps); type1 = typeof(int); } } } else { type = typeof(IntOps); type1 = typeof(int); } Expression expression = Expression.Call(type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic), target.Expression.Cast(target.LimitType).Cast(type1), arg.Expression.Cast(arg.LimitType).Cast(type1)); if (base.Operation == ExpressionType.Equal || base.Operation == ExpressionType.NotEqual) { Expression expression1 = expression; CatchBlock[] catchBlockArray = new CatchBlock[1]; CatchBlock[] catchBlockArray1 = catchBlockArray; int num = 0; Type type2 = typeof(InvalidCastException); if (base.Operation == ExpressionType.Equal) { boxedFalse = ExpressionCache.BoxedFalse; } else { boxedFalse = ExpressionCache.BoxedTrue; } catchBlockArray1[num] = Expression.Catch(type2, boxedFalse); expression = Expression.TryCatch(expression1, catchBlockArray); } DynamicMetaObject[] dynamicMetaObjectArray2 = new DynamicMetaObject[1]; dynamicMetaObjectArray2[0] = arg; return new DynamicMetaObject(expression, target.CombineRestrictions(dynamicMetaObjectArray2)); }
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); }