#nullable enable
using System.Dynamic;
using System.Linq.Expressions;
using IronPython.Runtime.Operations;
using Microsoft.Scripting.Runtime;
using Microsoft.Scripting.Utils;
namespace IronPython.Runtime.Binding {
using Ast = Expression;
internal class PythonSetSliceBinder : DynamicMetaObjectBinder, IPythonSite, IExpressionSerializable {
private readonly PythonContext _context;
public PythonSetSliceBinder(PythonContext context) {
_context = context;
}
public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
return PythonProtocol.Index(this, PythonIndexType.SetSlice, ArrayUtils.Insert(target, args));
}
public override int GetHashCode() {
return base.GetHashCode() ^ _context.Binder.GetHashCode();
}
public override bool Equals(object? obj) {
if (!(obj is PythonSetSliceBinder ob)) {
return false;
}
return ob._context.Binder == _context.Binder && base.Equals(obj);
}
#region IPythonSite Members
public PythonContext Context {
get { return _context; }
}
#endregion
#region IExpressionSerializable Members
public Expression CreateExpression() {
return Ast.Call(
typeof(PythonOps).GetMethod(nameof(PythonOps.MakeSetSliceBinder))!,
BindingHelpers.CreateBinderStateExpression()
);
}
#endregion
}
}