public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) { string str; Expression expression; Expression expression2; 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 { str = PSObject.ToStringParser(null, obj2.Value); expression = PSToStringBinder.InvokeToString(ExpressionCache.NullConstant, obj2.Expression); } DynamicMetaObject obj4 = PSSetMemberBinder.Get(str, this._static).FallbackSetMember(target, args[1]); BindingRestrictions restrictions = obj4.Restrictions.Merge(args[0].PSGetTypeRestriction()).Merge(BindingRestrictions.GetExpressionRestriction(Expression.Call(CachedReflectionInfo.String_Equals, Expression.Constant(str), expression, ExpressionCache.Ordinal))); if (target.Value is IDictionary) { ParameterExpression variable = Expression.Variable(typeof(Exception)); expression2 = Expression.TryCatch(PSSetIndexBinder.Get(1, null).FallbackSetIndex(target, new DynamicMetaObject[] { args[0] }, args[1]).Expression, new CatchBlock[] { Expression.Catch(variable, Expression.Block(Expression.Call(CachedReflectionInfo.CommandProcessorBase_CheckForSevereException, variable), obj4.Expression)) }); } else { expression2 = obj4.Expression; } return(new DynamicMetaObject(expression2, restrictions).WriteToDebugLog(this)); }
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)); }
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)); } } }
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)); }