mscorlib(4.0.0.0) API with additions
ArgMapper.cs
1 using System.Reflection;
3 using System.Security;
4 
6 {
7  internal class ArgMapper
8  {
9  private int[] _map;
10 
11  private IMethodMessage _mm;
12 
13  private RemotingMethodCachedData _methodCachedData;
14 
15  internal int[] Map => _map;
16 
17  internal int ArgCount
18  {
19  get
20  {
21  if (_map == null)
22  {
23  return 0;
24  }
25  return _map.Length;
26  }
27  }
28 
29  internal object[] Args
30  {
31  [SecurityCritical]
32  get
33  {
34  if (_map == null)
35  {
36  return null;
37  }
38  object[] array = new object[_map.Length];
39  for (int i = 0; i < _map.Length; i++)
40  {
41  array[i] = _mm.GetArg(_map[i]);
42  }
43  return array;
44  }
45  }
46 
47  internal Type[] ArgTypes
48  {
49  get
50  {
51  Type[] array = null;
52  if (_map != null)
53  {
54  ParameterInfo[] parameters = _methodCachedData.Parameters;
55  array = new Type[_map.Length];
56  for (int i = 0; i < _map.Length; i++)
57  {
58  array[i] = parameters[_map[i]].ParameterType;
59  }
60  }
61  return array;
62  }
63  }
64 
65  internal string[] ArgNames
66  {
67  get
68  {
69  string[] array = null;
70  if (_map != null)
71  {
72  ParameterInfo[] parameters = _methodCachedData.Parameters;
73  array = new string[_map.Length];
74  for (int i = 0; i < _map.Length; i++)
75  {
76  array[i] = parameters[_map[i]].Name;
77  }
78  }
79  return array;
80  }
81  }
82 
83  [SecurityCritical]
84  internal ArgMapper(IMethodMessage mm, bool fOut)
85  {
86  _mm = mm;
87  MethodBase methodBase = _mm.MethodBase;
88  _methodCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase);
89  if (fOut)
90  {
91  _map = _methodCachedData.MarshalResponseArgMap;
92  }
93  else
94  {
95  _map = _methodCachedData.MarshalRequestArgMap;
96  }
97  }
98 
99  [SecurityCritical]
100  internal ArgMapper(MethodBase mb, bool fOut)
101  {
102  _methodCachedData = InternalRemotingServices.GetReflectionCachedData(mb);
103  if (fOut)
104  {
105  _map = _methodCachedData.MarshalResponseArgMap;
106  }
107  else
108  {
109  _map = _methodCachedData.MarshalRequestArgMap;
110  }
111  }
112 
113  [SecurityCritical]
114  internal object GetArg(int argNum)
115  {
116  if (_map == null || argNum < 0 || argNum >= _map.Length)
117  {
118  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_InternalState"));
119  }
120  return _mm.GetArg(_map[argNum]);
121  }
122 
123  [SecurityCritical]
124  internal string GetArgName(int argNum)
125  {
126  if (_map == null || argNum < 0 || argNum >= _map.Length)
127  {
128  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_InternalState"));
129  }
130  return _mm.GetArgName(_map[argNum]);
131  }
132 
133  internal static void GetParameterMaps(ParameterInfo[] parameters, out int[] inRefArgMap, out int[] outRefArgMap, out int[] outOnlyArgMap, out int[] nonRefOutArgMap, out int[] marshalRequestMap, out int[] marshalResponseMap)
134  {
135  int num = 0;
136  int num2 = 0;
137  int num3 = 0;
138  int num4 = 0;
139  int num5 = 0;
140  int num6 = 0;
141  int[] array = new int[parameters.Length];
142  int[] array2 = new int[parameters.Length];
143  int num7 = 0;
144  foreach (ParameterInfo parameterInfo in parameters)
145  {
146  bool isIn = parameterInfo.IsIn;
147  bool isOut = parameterInfo.IsOut;
148  bool isByRef = parameterInfo.ParameterType.IsByRef;
149  if (!isByRef)
150  {
151  num++;
152  if (isOut)
153  {
154  num4++;
155  }
156  }
157  else if (isOut)
158  {
159  num2++;
160  num3++;
161  }
162  else
163  {
164  num++;
165  num2++;
166  }
167  bool flag = false;
168  bool flag2 = false;
169  if (isByRef)
170  {
171  if (isIn == isOut)
172  {
173  flag = true;
174  flag2 = true;
175  }
176  else
177  {
178  flag = isIn;
179  flag2 = isOut;
180  }
181  }
182  else
183  {
184  flag = true;
185  flag2 = isOut;
186  }
187  if (flag)
188  {
189  array[num5++] = num7;
190  }
191  if (flag2)
192  {
193  array2[num6++] = num7;
194  }
195  num7++;
196  }
197  inRefArgMap = new int[num];
198  outRefArgMap = new int[num2];
199  outOnlyArgMap = new int[num3];
200  nonRefOutArgMap = new int[num4];
201  num = 0;
202  num2 = 0;
203  num3 = 0;
204  num4 = 0;
205  for (num7 = 0; num7 < parameters.Length; num7++)
206  {
207  ParameterInfo parameterInfo2 = parameters[num7];
208  bool isOut2 = parameterInfo2.IsOut;
209  if (!parameterInfo2.ParameterType.IsByRef)
210  {
211  inRefArgMap[num++] = num7;
212  if (isOut2)
213  {
214  nonRefOutArgMap[num4++] = num7;
215  }
216  }
217  else if (isOut2)
218  {
219  outRefArgMap[num2++] = num7;
220  outOnlyArgMap[num3++] = num7;
221  }
222  else
223  {
224  inRefArgMap[num++] = num7;
225  outRefArgMap[num2++] = num7;
226  }
227  }
228  marshalRequestMap = new int[num5];
229  Array.Copy(array, marshalRequestMap, num5);
230  marshalResponseMap = new int[num6];
231  Array.Copy(array2, marshalResponseMap, num6);
232  }
233 
234  internal static object[] ExpandAsyncEndArgsToSyncArgs(RemotingMethodCachedData syncMethod, object[] asyncEndArgs)
235  {
236  object[] array = new object[syncMethod.Parameters.Length];
237  int[] outRefArgMap = syncMethod.OutRefArgMap;
238  for (int i = 0; i < outRefArgMap.Length; i++)
239  {
240  array[outRefArgMap[i]] = asyncEndArgs[i];
241  }
242  return array;
243  }
244  }
245 }
Discovers the attributes of a parameter and provides access to parameter metadata.
MethodBase MethodBase
Gets the T:System.Reflection.MethodBase of the called method.
string GetArgName(int index)
Gets the name of the argument passed to the method.
Definition: __Canon.cs:3
bool IsIn
Gets a value indicating whether this is an input parameter.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
object GetArg(int argNum)
Gets a specific argument as an T:System.Object.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
Defines utility methods for use by the .NET Framework remoting infrastructure.
Provides information about methods and constructors.
Definition: MethodBase.cs:19
Defines the method message interface.
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Definition: Array.cs:1275
bool IsOut
Gets a value indicating whether this is an output parameter.
virtual Type ParameterType
Gets the Type of this parameter.
The exception that is thrown when a method call is invalid for the object's current state.
bool IsByRef
Gets a value indicating whether the T:System.Type is passed by reference.
Definition: Type.cs:664
virtual string Name
Gets the name of the parameter.