PageRenderTime 28ms CodeModel.GetById 16ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/IronPython_2_0/Src/IronPython/Runtime/Binding/SetMemberBinder.cs

#
C# | 89 lines | 57 code | 18 blank | 14 comment | 5 complexity | 7679669b4b5e136700742d4e6c81f7c9 MD5 | raw file
 1/* ****************************************************************************
 2*
 3* Copyright (c) Microsoft Corporation. 
 4*
 5* This source code is subject to terms and conditions of the Microsoft Public License. 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  Microsoft Public License, 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 Microsoft Public License.
10*
11* You must not remove this notice, or any other, from this software.
12*
13*
14* ***************************************************************************/
15
16using System; using Microsoft;
17using Microsoft.Scripting;
18using Microsoft.Scripting.Actions;
19using Microsoft.Linq.Expressions;
20using Microsoft.Scripting.Runtime;
21
22using IronPython.Runtime.Binding;
23using IronPython.Runtime.Operations;
24using IronPython.Runtime.Types;
25
26namespace IronPython.Runtime.Binding {
27    using Ast = Microsoft.Linq.Expressions.Expression;
28
29    class SetMemberBinder : SetMemberAction, IPythonSite, IExpressionSerializable {
30        private readonly BinderState/*!*/ _state;
31
32        public SetMemberBinder(BinderState/*!*/ binder, string/*!*/ name)
33            : this(binder, name, false) {
34        }
35
36        public SetMemberBinder(BinderState/*!*/ binder, string/*!*/ name, bool caseInsensitive)
37            : base(name, caseInsensitive) {
38            _state = binder;
39        }
40
41        public override MetaObject Fallback(MetaObject self, MetaObject value, MetaObject onBindingError) {
42            if (self.NeedsDeferral()) {
43                return Defer(self, value);
44            }
45
46            return Binder.Binder.SetMember(Name, self, value, Ast.Constant(Binder.Context));
47        }
48
49        public BinderState/*!*/ Binder {
50            get {
51                return _state;
52            }
53        }
54
55        public override object HashCookie {
56            get { return this; }
57        }
58
59        public override int GetHashCode() {
60            return base.GetHashCode() ^ _state.Binder.GetHashCode();
61        }
62
63        public override bool Equals(object obj) {
64            SetMemberBinder ob = obj as SetMemberBinder;
65            if (ob == null) {
66                return false;
67            }
68
69            return ob._state.Binder == _state.Binder && base.Equals(obj);
70        }
71
72        public override string ToString() {
73            return "Python SetMember " + Name;
74        }
75
76        #region IExpressionSerializable Members
77
78        public Expression CreateExpression() {
79            return Ast.Call(
80                typeof(PythonOps).GetMethod("MakeSetAction"),
81                BindingHelpers.CreateBinderStateExpression(),
82                Ast.Constant(Name)
83            );
84        }
85
86        #endregion
87    }
88}
89