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)); }