Merge pull request #572 from jack-pappas/sockets-ipproto
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Scripting.Core / Actions / SetMemberBinder.cs
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 using System.Dynamic.Utils;
17
18 namespace System.Dynamic {
19     /// <summary>
20     /// Represents the dynamic set member operation at the call site, providing the binding semantic and the details about the operation.
21     /// </summary>
22     public abstract class SetMemberBinder : DynamicMetaObjectBinder {
23         private readonly string _name;
24         private readonly bool _ignoreCase;
25
26         /// <summary>
27         /// Initializes a new instance of the <see cref="SetMemberBinder" />.
28         /// </summary>
29         /// <param name="name">The name of the member to get.</param>
30         /// <param name="ignoreCase">true if the name should be matched ignoring case; false otherwise.</param>
31         protected SetMemberBinder(string name, bool ignoreCase) {
32             ContractUtils.RequiresNotNull(name, "name");
33
34             _name = name;
35             _ignoreCase = ignoreCase;
36         }
37
38         /// <summary>
39         /// The result type of the operation.
40         /// </summary>
41         public override sealed Type ReturnType {
42             get { return typeof(object); }
43         }
44
45         /// <summary>
46         /// Gets the name of the member to get.
47         /// </summary>
48         public string Name {
49             get {
50                 return _name;
51             }
52         }
53
54         /// <summary>
55         /// Gets the value indicating if the string comparison should ignore the case of the member name.
56         /// </summary>
57         public bool IgnoreCase {
58             get {
59                 return _ignoreCase;
60             }
61         }
62
63         /// <summary>
64         /// Performs the binding of the dynamic set member operation.
65         /// </summary>
66         /// <param name="target">The target of the dynamic set member operation.</param>
67         /// <param name="args">An array of arguments of the dynamic set member operation.</param>
68         /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
69         public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
70             ContractUtils.RequiresNotNull(target, "target");
71             ContractUtils.RequiresNotNull(args, "args");
72             ContractUtils.Requires(args.Length == 1, "args");
73
74             var arg0 = args[0];
75             ContractUtils.RequiresNotNull(arg0, "args");
76
77             return target.BindSetMember(this, arg0);
78         }
79
80         // this is a standard DynamicMetaObjectBinder
81         internal override sealed bool IsStandardBinder {
82             get {
83                 return true;
84             }
85         }
86
87         /// <summary>
88         /// Performs the binding of the dynamic set member operation if the target dynamic object cannot bind.
89         /// </summary>
90         /// <param name="target">The target of the dynamic set member operation.</param>
91         /// <param name="value">The value to set to the member.</param>
92         /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
93         public DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value) {
94             return FallbackSetMember(target, value, null);
95         }
96
97         /// <summary>
98         /// Performs the binding of the dynamic set member operation if the target dynamic object cannot bind.
99         /// </summary>
100         /// <param name="target">The target of the dynamic set member operation.</param>
101         /// <param name="value">The value to set to the member.</param>
102         /// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
103         /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
104         public abstract DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion);
105     }
106 }