115c4d917f1efd27c961bb7833a441342e813f07
[mono.git] / mcs / mcs / support.cs
1 //
2 // support.cs: Support routines to work around the fact that System.Reflection.Emit
3 // can not introspect types that are being constructed
4 //
5 // Author:
6 //   Miguel de Icaza (miguel@ximian.com)
7 //
8 // (C) 2001 Ximian, Inc (http://www.ximian.com)
9 //
10
11 using System.Reflection.Emit;
12 using System.Reflection;
13 using System;
14 using System.Text;
15
16 namespace CIR {
17
18         public interface ParameterData {
19                 Type ParameterType (int pos);
20                 int  Count { get; }
21                 string ParameterDesc (int pos);
22         }
23
24         public class ReflectionParameters : ParameterData {
25                 ParameterInfo [] pi;
26
27                 public ReflectionParameters (ParameterInfo [] pi)
28                 {
29                         this.pi = pi;
30                 }
31                        
32                 public Type ParameterType (int pos)
33                 {
34                         return pi [pos].ParameterType;
35                 }
36
37                 public string ParameterDesc (int pos)
38                 {
39                         StringBuilder sb = new StringBuilder ();
40
41                         if (pi [pos].IsOut)
42                                 sb.Append ("out ");
43
44                         if (pi [pos].IsIn)
45                                 sb.Append ("in ");
46
47                         sb.Append (TypeManager.CSharpName (ParameterType (pos)));
48
49                         return sb.ToString ();
50                         
51                 }
52
53                 public int Count {
54                         get {
55                                 return pi.Length;
56                         }
57                 }
58                 
59         }
60
61         public class InternalParameters : ParameterData {
62                 Type [] pars;
63                 
64                 public InternalParameters (Type [] pars)
65                 {
66                         this.pars = pars;
67                 }
68
69                 public int Count {
70                         get {
71                                 if (pars == null)
72                                         return 0;
73                                 
74                                 return pars.Length;
75                         }
76                 }
77
78                 public Type ParameterType (int pos)
79                 {
80                         if (pars == null)
81                                 return null;
82                                         
83                         return pars [pos];
84                 }
85
86                 public string ParameterDesc (int pos)
87                 {
88                         return TypeManager.CSharpName (ParameterType (pos));
89                 }
90         }
91 }