Merge pull request #1631 from alexanderkyte/stringbuilder-referencesource
[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         [System.Runtime.InteropServices.ComVisible (true)]
40         public class MethodCallMessageWrapper : InternalMessageWrapper, IMethodCallMessage, IMethodMessage, IMessage
41         {
42                 object[] _args;
43                 ArgInfo _inArgInfo;
44                 DictionaryWrapper _properties;
45
46                 public MethodCallMessageWrapper (IMethodCallMessage msg)
47                         : base (msg)
48                 {
49                         _args = ((IMethodCallMessage)WrappedMessage).Args;
50                         _inArgInfo = new ArgInfo (msg.MethodBase, ArgInfoType.In);
51                 }
52                 
53                 public virtual int ArgCount {
54                         get { return ((IMethodCallMessage)WrappedMessage).ArgCount; }
55                 }
56
57                 public virtual object [] Args {
58                         get { return _args; }
59                         set { _args = value; }
60                 }
61                 
62                 public virtual bool HasVarArgs {
63                         get { return ((IMethodCallMessage)WrappedMessage).HasVarArgs; }
64                 }
65
66                 public virtual int InArgCount {
67                         get { return _inArgInfo.GetInOutArgCount(); }
68                 }
69
70                 public virtual object[] InArgs {
71                         get { return _inArgInfo.GetInOutArgs (_args); }
72                 }
73                 
74                 public virtual LogicalCallContext LogicalCallContext {
75                         get { return ((IMethodCallMessage)WrappedMessage).LogicalCallContext; }
76                 }
77                 
78                 public virtual MethodBase MethodBase {
79                         get { return ((IMethodCallMessage)WrappedMessage).MethodBase; }
80                 }
81
82                 public virtual string MethodName {
83                         get { return ((IMethodCallMessage)WrappedMessage).MethodName; }
84                 }
85
86                 public virtual object MethodSignature {
87                         get { return ((IMethodCallMessage)WrappedMessage).MethodSignature; }
88                 }
89                 
90                 public virtual IDictionary Properties 
91                 {
92                         get 
93                         { 
94                                 if (_properties == null) _properties = new DictionaryWrapper(this, WrappedMessage.Properties);
95                                 return _properties; 
96                         }
97                 }
98
99                 public virtual string TypeName {
100                         get { return ((IMethodCallMessage)WrappedMessage).TypeName; }
101                 }
102
103                 public virtual string Uri {
104                         get { return ((IMethodCallMessage)WrappedMessage).Uri; }
105                         set {
106                                 IInternalMessage im = WrappedMessage as IInternalMessage;
107                                 if (im != null) im.Uri = value;
108                                 else Properties["__Uri"] = value; 
109                         }
110                 }
111
112                 public virtual object GetArg (int argNum)
113                 {
114                         return _args[argNum];
115                 }
116
117                 public virtual string GetArgName (int index)
118                 {
119                         return ((IMethodCallMessage)WrappedMessage).GetArgName (index);
120                 }
121
122                 public virtual object GetInArg (int argNum)
123                 {
124                         return _args[_inArgInfo.GetInOutArgIndex (argNum)];
125                 }
126
127                 public virtual string GetInArgName (int index)
128                 {
129                         return _inArgInfo.GetInOutArgName(index);
130                 }
131
132                 class DictionaryWrapper : MCMDictionary
133                 {
134                         IDictionary _wrappedDictionary;
135                         static string[] _keys = new string[] {"__Args"};
136
137                         public DictionaryWrapper(IMethodMessage message, IDictionary wrappedDictionary) : base (message)
138                         {
139                                 _wrappedDictionary = wrappedDictionary;
140                                 MethodKeys = _keys;
141                         }
142
143                         protected override IDictionary AllocInternalProperties()
144                         {
145                                 return _wrappedDictionary;
146                         }
147
148                         protected override void SetMethodProperty (string key, object value)
149                         {
150                                 if (key == "__Args") ((MethodCallMessageWrapper)_message)._args = (object[])value;
151                                 else base.SetMethodProperty (key, value);
152                         }
153
154                         protected override object GetMethodProperty (string key)
155                         {
156                                 if (key == "__Args") return ((MethodCallMessageWrapper)_message)._args;
157                                 else return base.GetMethodProperty (key);
158                         }
159                 }
160         }
161 }