Expression IAssignableValue.SetValue(Compiler compiler, Expression rhs) { IEnumerable <PropertyInfo> enumerable; bool flag; if (this.VariablePath.IsVariable && this.VariablePath.UnqualifiedPath.Equals("null", StringComparison.OrdinalIgnoreCase)) { return(rhs); } Type type = this.GetVariableType(compiler, out enumerable, out flag); Type type2 = rhs.Type; if ((flag && (type.Equals(typeof(object)) || type.Equals(typeof(PSObject)))) && (type2.Equals(typeof(object)) || type2.Equals(typeof(PSObject)))) { rhs = Expression.Dynamic(PSVariableAssignmentBinder.Get(), typeof(object), rhs); } rhs = rhs.Convert(type); if (!flag) { return(Compiler.CallSetVariable(Expression.Constant(this.VariablePath), rhs, null)); } Expression localVariablesParameter = compiler.LocalVariablesParameter; foreach (PropertyInfo info in enumerable) { localVariablesParameter = Expression.Property(localVariablesParameter, info); } return(Expression.Assign(localVariablesParameter, rhs)); }
public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) { if (!target.HasValue) { return(base.Defer(target, args)); } if (target.Value == AutomationNull.Value) { return(new DynamicMetaObject(Expression.Block(typeof(void), new Expression[] { Expression.Call(CachedReflectionInfo.PipelineOps_Nop, new Expression[0]) }), BindingRestrictions.GetInstanceRestriction(target.Expression, AutomationNull.Value)).WriteToDebugLog(this)); } DynamicMetaObject obj2 = PSEnumerableBinder.IsEnumerable(target); if (obj2 == null) { DynamicMetaObject obj3 = PSVariableAssignmentBinder.Get().Bind(target, new DynamicMetaObject[0]); BindingRestrictions restrictions = target.LimitType.IsValueType ? obj3.Restrictions : target.PSGetTypeRestriction(); return(new DynamicMetaObject(Expression.Call(args[0].Expression, CachedReflectionInfo.Pipe_Add, new Expression[] { obj3.Expression.Cast(typeof(object)) }), restrictions).WriteToDebugLog(this)); } bool b = !(PSObject.Base(target.Value) is IEnumerator); return(new DynamicMetaObject(Expression.Call(CachedReflectionInfo.EnumerableOps_WriteEnumerableToPipe, obj2.Expression, args[0].Expression, args[1].Expression, ExpressionCache.Constant(b)), obj2.Restrictions).WriteToDebugLog(this)); }
private static bool MustBeBoxed(Type type) { return((type.IsValueType && PSVariableAssignmentBinder.IsValueTypeMutable(type)) && !typeof(SwitchParameter).Equals(type)); }