2 // parameter.cs: Parameter definition.
4 // Author: Miguel de Icaza (miguel@gnu.org)
6 // Licensed under the terms of the GNU GPL
8 // (C) 2001 Ximian, Inc (http://www.ximian.com)
16 using System.Reflection;
17 using System.Collections;
19 public class Parameter {
20 public enum Modifier {
27 public readonly string Type;
28 public readonly string Name;
29 public readonly Modifier ModFlags;
30 public Attributes OptAttributes;
32 public Parameter (string type, string name, Modifier mod, Attributes attrs)
37 OptAttributes = attrs;
40 public ParameterAttributes Attributes {
44 return ParameterAttributes.None;
46 return ParameterAttributes.None;
48 return ParameterAttributes.Out;
53 return ParameterAttributes.None;
57 string ModSignature ()
69 // This should not happen.
74 // Returns the signature for this parameter evaluating it on the
77 public string GetSignature (TypeContainer tc)
79 Type t = tc.LookupType (Type, false);
84 return ModSignature () + t.FullName;
88 public class Parameters {
89 public Parameter [] FixedParameters;
90 public readonly Parameter ArrayParameter;
94 public Parameters (Parameter [] fixed_parameters, Parameter array_parameter)
96 FixedParameters = fixed_parameters;
97 ArrayParameter = array_parameter;
102 return (FixedParameters == null) && (ArrayParameter == null);
106 public void ComputeSignature (TypeContainer tc)
109 if (FixedParameters != null){
110 for (int i = 0; i < FixedParameters.Length; i++){
111 Parameter par = FixedParameters [i];
113 signature += par.GetSignature (tc);
117 // Note: as per the spec, the `params' arguments (ArrayParameter)
118 // are not used in the signature computation for a method
122 public bool VerifyArgs (TypeContainer tc)
127 if (FixedParameters == null)
130 count = FixedParameters.Length;
131 for (i = 0; i < count; i++){
132 for (j = i + 1; j < count; j++){
133 if (FixedParameters [i].Name != FixedParameters [j].Name)
136 100, "The parameter name `" + FixedParameters [i].Name +
145 // Returns the signature of the Parameters evaluated in
146 // the @tc environment
148 public string GetSignature (TypeContainer tc)
150 if (signature == null){
152 ComputeSignature (tc);
159 // Returns the paramenter information based on the name
161 public Parameter GetParameterByName (string name, out int idx)
165 if (FixedParameters == null)
169 foreach (Parameter par in FixedParameters){
170 if (par.Name == name){
182 // Returns the argument types as an array
184 public Type [] GetParameterInfo (TypeContainer tc)
189 if (FixedParameters == null)
192 int extra = (ArrayParameter != null) ? 1 : 0;
194 int pc = FixedParameters.Length + extra;
196 types = new Type [pc];
198 if (!VerifyArgs (tc)){
199 FixedParameters = null;
203 foreach (Parameter p in FixedParameters){
204 Type t = tc.LookupType (p.Type, false);
206 if ((p.ModFlags & (Parameter.Modifier.REF | Parameter.Modifier.OUT)) != 0){
207 t = Type.GetType (t.FullName + "&");
214 types [i] = Type.GetType ("System.Object");
219 public CallingConventions GetCallingConvention ()
221 if (ArrayParameter != null)
222 return CallingConventions.VarArgs;
224 return CallingConventions.Standard;