2009-07-02 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / class / Microsoft.CSharp / Microsoft.CSharp.RuntimeBinder / CSharpInvokeMemberBinder.cs
1 //
2 // CSharpInvokeMemberBinder.cs
3 //
4 // Authors:
5 //      Marek Safar  <marek.safar@gmail.com>
6 //
7 // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Dynamic;
31 using System.Collections.Generic;
32 using System.Linq;
33 using System.Runtime.CompilerServices;
34
35 namespace Microsoft.CSharp.RuntimeBinder
36 {
37         public class CSharpInvokeMemberBinder : InvokeMemberBinder
38         {
39                 CSharpCallFlags flags;
40                 IList<CSharpArgumentInfo> argumentInfo;
41                 IList<Type> typeArguments;
42                 Type callingContext;
43                 
44                 public CSharpInvokeMemberBinder (CSharpCallFlags flags, string name, Type callingContext, IEnumerable<Type> typeArguments, IEnumerable<CSharpArgumentInfo> argumentInfo)
45                         : base (name, false, CreateCallInfo (argumentInfo))
46                 {
47                         this.flags = flags;
48                         this.callingContext = callingContext;
49                         this.argumentInfo = new ReadOnlyCollectionBuilder<CSharpArgumentInfo> (argumentInfo);
50                         this.typeArguments = new ReadOnlyCollectionBuilder<Type> (typeArguments);
51                 }
52                 
53                 static CallInfo CreateCallInfo (IEnumerable<CSharpArgumentInfo> argumentInfo)
54                 {
55                         var named = from arg in argumentInfo where arg.IsNamed select arg.Name;
56                         return new CallInfo (argumentInfo.Count (), named);
57                 }
58                 
59                 public IList<CSharpArgumentInfo> ArgumentInfo {
60                         get {
61                                 return argumentInfo;
62                         }
63                 }
64
65                 public Type CallingContext {
66                         get {
67                                 return callingContext;
68                         }
69                 }
70                 
71                 public override bool Equals (object obj)
72                 {
73                         var other = obj as CSharpInvokeMemberBinder;
74                         return other != null && base.Equals (obj) && other.flags == flags && other.callingContext == callingContext && 
75                                 other.argumentInfo.SequenceEqual (argumentInfo) && other.typeArguments.SequenceEqual (typeArguments);
76                 }
77
78                 public CSharpCallFlags Flags {
79                         get {
80                                 return flags;
81                         }
82                 }
83                 
84                 public override int GetHashCode ()
85                 {
86                         return base.GetHashCode ();
87                 }
88                 
89                 [MonoTODO]
90                 public override DynamicMetaObject FallbackInvoke (DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
91                 {
92                         throw new NotImplementedException ();
93                 }
94                 
95                 [MonoTODO]
96                 public override DynamicMetaObject FallbackInvokeMember (DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
97                 {
98                         throw new NotImplementedException ();                   
99                 }
100                 
101                 public IList<Type> TypeArguments {
102                         get {
103                                 return typeArguments;
104                         }
105                 }
106         }
107 }