1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
5 using System.Diagnostics;
7 namespace System.Reflection.TypeLoading
9 // This helper class represents a combined return value info and parameter info array. It is motivated by the fact that
10 // the Reflection api surfaces "return types" as a "ParameterInfo at position -1." (and that the Ecma-335 metadata
11 // scheme similarly reuses the Parameter table for holding return type custom attributes and stuff.)
13 // Behaviorally, it acts like an array whose lower bound is -1 (where the "-1"th element is the "return" ParameterInfo).
15 // It also allows getting an array of the parameters (excluding the return value) without copying.
17 // The name is motivated by System.Reflection.Metadata using the name MethodSignature<T> for a similar concept and
18 // that it's far shorter than "ParametersAndReturnType".
19 internal sealed class MethodSig<T>
21 public T Return { get; private set; }
22 public T[] Parameters { get; }
24 public MethodSig(int parameterCount)
26 Debug.Assert(parameterCount >= 0);
27 Parameters = new T[parameterCount];
30 public T this[int position]
34 Debug.Assert(position >= -1 && position < Parameters.Length);
35 return position == -1 ? Return : Parameters[position];
40 Debug.Assert(position >= -1 && position < Parameters.Length);
47 Parameters[position] = value;