PageRenderTime 17ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Languages/IronPython/IronPython/Runtime/Binding/PythonDeleteSliceBinder.cs

#
C# | 76 lines | 45 code | 17 blank | 14 comment | 4 complexity | 06b6b3ccebf2102dae2aac1d2a7f4b92 MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the  Apache License, Version 2.0, please send an email to 
 8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Apache License, Version 2.0.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15
16#if !CLR2
17using System.Linq.Expressions;
18#else
19using Microsoft.Scripting.Ast;
20#endif
21
22using System;
23using System.Dynamic;
24
25using Microsoft.Scripting.Runtime;
26using Microsoft.Scripting.Utils;
27
28using IronPython.Runtime.Operations;
29
30namespace IronPython.Runtime.Binding {
31    using Ast = Expression;
32
33    class PythonDeleteSliceBinder : DynamicMetaObjectBinder, IPythonSite, IExpressionSerializable {
34        private readonly PythonContext/*!*/ _context;
35
36        public PythonDeleteSliceBinder(PythonContext/*!*/ context) {
37            _context = context;
38        }
39
40        public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
41            return PythonProtocol.Index(this, PythonIndexType.DeleteSlice, ArrayUtils.Insert(target, args));
42        }
43
44        public override int GetHashCode() {
45            return base.GetHashCode() ^ _context.Binder.GetHashCode();
46        }
47
48        public override bool Equals(object obj) {
49            PythonDeleteSliceBinder ob = obj as PythonDeleteSliceBinder;
50            if (ob == null) {
51                return false;
52            }
53
54            return ob._context.Binder == _context.Binder && base.Equals(obj);
55        }
56
57        #region IPythonSite Members
58
59        public PythonContext/*!*/ Context {
60            get { return _context; }
61        }
62
63        #endregion
64
65        #region IExpressionSerializable Members
66
67        public Expression/*!*/ CreateExpression() {
68            return Ast.Call(
69                typeof(PythonOps).GetMethod("MakeDeleteSliceBinder"),
70                BindingHelpers.CreateBinderStateExpression()
71            );
72        }
73
74        #endregion
75    }
76}