* Mono.Posix.dll.sources: Rename Mono.Posix to Mono.Unix.
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / MethodCallMessageWrapper.cs
1 //
2 // System.Runtime.Remoting.Messaging.MethodCallMessageWrapper.cs
3 //
4 // Author: Duncan Mak (duncan@ximian.com)
5 //         Lluis Sanchez Gual (lluis@ideary.com)
6 //
7 // 2002 (C) Copyright, Ximian, Inc.
8 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System;
34 using System.Collections;
35 using System.Reflection;
36
37 namespace System.Runtime.Remoting.Messaging {
38
39         public class MethodCallMessageWrapper : InternalMessageWrapper, IMethodCallMessage, IMethodMessage, IMessage
40         {
41                 object[] _args;
42                 ArgInfo _inArgInfo;
43                 DictionaryWrapper _properties;
44
45                 public MethodCallMessageWrapper (IMethodCallMessage msg)
46                         : base (msg)
47                 {
48                         _args = ((IMethodCallMessage)WrappedMessage).Args;
49                         _inArgInfo = new ArgInfo (msg.MethodBase, ArgInfoType.In);
50                 }
51                 
52                 public virtual int ArgCount {
53                         get { return ((IMethodCallMessage)WrappedMessage).ArgCount; }
54                 }
55
56                 public virtual object [] Args {
57                         get { return _args; }
58                         set { _args = value; }
59                 }
60                 
61                 public virtual bool HasVarArgs {
62                         get { return ((IMethodCallMessage)WrappedMessage).HasVarArgs; }
63                 }
64
65                 public int InArgCount {
66                         get  { return _inArgInfo.GetInOutArgCount(); }
67                 }
68
69                 public object[] InArgs {
70                         get { return _inArgInfo.GetInOutArgs (_args); }
71                 }
72                 
73                 public virtual LogicalCallContext LogicalCallContext {
74                         get { return ((IMethodCallMessage)WrappedMessage).LogicalCallContext; }
75                 }
76                 
77                 public virtual MethodBase MethodBase {
78                         get { return ((IMethodCallMessage)WrappedMessage).MethodBase; }
79                 }
80
81                 public virtual string MethodName {
82                         get { return ((IMethodCallMessage)WrappedMessage).MethodName; }
83                 }
84
85                 public virtual object MethodSignature {
86                         get { return ((IMethodCallMessage)WrappedMessage).MethodSignature; }
87                 }
88                 
89                 public virtual IDictionary Properties 
90                 {
91                         get 
92                         { 
93                                 if (_properties == null) _properties = new DictionaryWrapper(this, WrappedMessage.Properties);
94                                 return _properties; 
95                         }
96                 }
97
98                 public virtual string TypeName {
99                         get { return ((IMethodCallMessage)WrappedMessage).TypeName; }
100                 }
101
102                 public virtual string Uri {
103                         get { return ((IMethodCallMessage)WrappedMessage).Uri; }
104                         set {
105                                 IInternalMessage im = WrappedMessage as IInternalMessage;
106                                 if (im != null) im.Uri = value;
107                                 else Properties["__Uri"] = value; 
108                         }
109                 }
110
111                 public virtual object GetArg (int argNum)
112                 {
113                         return _args[argNum];
114                 }
115
116                 public virtual string GetArgName (int index)
117                 {
118                         return ((IMethodCallMessage)WrappedMessage).GetArgName (index);
119                 }
120
121                 public object GetInArg (int argNum)
122                 {
123                         return _args[_inArgInfo.GetInOutArgIndex (argNum)];
124                 }
125
126                 public string GetInArgName (int index)
127                 {
128                         return _inArgInfo.GetInOutArgName(index);
129                 }
130
131                 class DictionaryWrapper : MethodCallDictionary\r
132                 {\r
133                         IDictionary _wrappedDictionary;\r
134                         static string[] _keys = new string[] {"__Args"};\r
135 \r
136                         public DictionaryWrapper(IMethodMessage message, IDictionary wrappedDictionary) : base (message)\r
137                         {\r
138                                 _wrappedDictionary = wrappedDictionary;\r
139                                 MethodKeys = _keys;\r
140                         }\r
141
142                         protected override IDictionary AllocInternalProperties()\r
143                         {\r
144                                 return _wrappedDictionary;\r
145                         }\r
146
147                         protected override void SetMethodProperty (string key, object value)
148                         {
149                                 if (key == "__Args") ((MethodCallMessageWrapper)_message)._args = (object[])value;
150                                 else base.SetMethodProperty (key, value);
151                         }
152
153                         protected override object GetMethodProperty (string key)
154                         {
155                                 if (key == "__Args") return ((MethodCallMessageWrapper)_message)._args;
156                                 else return base.GetMethodProperty (key);
157                         }
158                 }
159         }
160 }