/// <summary> /// Tries to perform binding of the dynamic invoke member operation. /// </summary> /// <param name="binder">An instance of the <see cref="InvokeMemberBinder"/> that represents the details of the dynamic operation.</param> /// <param name="isSetProperty">True if this is for setting a property, false otherwise.</param> /// <param name="instance">The target of the dynamic operation.</param> /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param> /// <param name="result">The new <see cref="DynamicMetaObject"/> representing the result of the binding.</param> /// <returns>True if operation was bound successfully; otherwise, false.</returns> public static bool TryBindInvokeMember(InvokeMemberBinder binder, bool isSetProperty, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) { if (TryGetMetaObject(ref instance)) { var comInvokeMember = new ComInvokeMemberBinder(binder, isSetProperty); result = instance.BindInvokeMember(comInvokeMember, args); BindingRestrictions argRestrictions = args.Aggregate( BindingRestrictions.Empty, (current, arg) => current.Merge(arg.PSGetMethodArgumentRestriction())); var newRestrictions = result.Restrictions.Merge(argRestrictions); if (result.Expression.Type.IsValueType) { result = new DynamicMetaObject( Expression.Convert(result.Expression, typeof(object)), newRestrictions ); } else { result = new DynamicMetaObject(result.Expression, newRestrictions); } return(true); } else { result = null; return(false); } }
public override bool Equals(object obj) { ComInvokeMemberBinder other = obj as ComInvokeMemberBinder; return(other != null && IsPropertySet == other.IsPropertySet && _originalBinder.Equals(other._originalBinder)); }
/// <summary> /// Tries to perform binding of the dynamic invoke member operation. /// </summary> /// <param name="binder">An instance of the <see cref="InvokeMemberBinder"/> that represents the details of the dynamic operation.</param> /// <param name="isSetProperty">True if this is for setting a property, false otherwise..</param> /// <param name="instance">The target of the dynamic operation. </param> /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke member operation.</param> /// <param name="result">The new <see cref="DynamicMetaObject"/> representing the result of the binding.</param> /// <returns>true if operation was bound successfully; otherwise, false.</returns> public static bool TryBindInvokeMember(InvokeMemberBinder binder, bool isSetProperty, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) { if (TryGetMetaObject(ref instance)) { var comInvokeMember = new ComInvokeMemberBinder(binder, isSetProperty); result = instance.BindInvokeMember(comInvokeMember, args); BindingRestrictions argRestrictions = args.Aggregate( BindingRestrictions.Empty, (current, arg) => current.Merge(arg.PSGetMethodArgumentRestriction())); var newRestrictions = result.Restrictions.Merge(argRestrictions); if (result.Expression.Type.IsValueType) { result = new DynamicMetaObject( Expression.Convert(result.Expression, typeof(object)), newRestrictions ); } else { result = new DynamicMetaObject(result.Expression, newRestrictions); } return true; } else { result = null; return false; } }