2003-12-17 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / System.Reflection / ParameterInfo.cs
1 // System.Reflection.ParameterInfo
2 //
3 // Sean MacIsaac (macisaac@ximian.com)
4 //
5 // (C) 2001 Ximian, Inc.
6
7 using System.Reflection.Emit;
8
9 namespace System.Reflection
10 {
11         [Serializable]
12         public class ParameterInfo : ICustomAttributeProvider
13         {
14                 protected Type ClassImpl;
15                 protected object DefaultValueImpl;
16                 protected MemberInfo MemberImpl;
17                 protected string NameImpl;
18                 protected int PositionImpl;
19                 protected ParameterAttributes AttrsImpl;
20
21                 protected ParameterInfo () {
22                 }
23
24                 internal ParameterInfo (ParameterBuilder pb, Type type, MemberInfo member, int position) {
25                         this.ClassImpl = type;
26                         this.MemberImpl = member;
27                         if (pb != null) {
28                                 this.NameImpl = pb.Name;
29                                 this.PositionImpl = pb.Position - 1;    // ParameterInfo.Position is zero-based
30                                 this.AttrsImpl = (ParameterAttributes) pb.Attributes;
31                         } else {
32                                 this.NameImpl = "";
33                                 this.PositionImpl = position - 1;
34                                 this.AttrsImpl = ParameterAttributes.None;
35                         }
36                 }
37
38                 /* to build a ParameterInfo for the return type of a method */
39                 internal ParameterInfo (Type type, MemberInfo member) {
40                         this.ClassImpl = type;
41                         this.MemberImpl = member;
42                         this.NameImpl = "";
43                         this.PositionImpl = -1; // since parameter positions are zero-based, return type pos is -1
44                         this.AttrsImpl = ParameterAttributes.Retval;
45                 }
46                 
47                 public virtual Type ParameterType {
48                         get {return ClassImpl;}
49                 }
50                 public virtual ParameterAttributes Attributes {
51                         get {return AttrsImpl;}
52                 }
53                 public virtual object DefaultValue {
54                         get {return DefaultValueImpl;}
55                 }
56
57                 public bool IsIn {
58                         get {return (AttrsImpl & ParameterAttributes.In) != 0;}
59                 }
60
61                 public bool IsLcid {
62                         get {return (AttrsImpl & ParameterAttributes.Lcid) != 0;}
63                 }
64
65                 public bool IsOptional {
66                         get {return (AttrsImpl & ParameterAttributes.Optional) != 0;}
67                 }
68
69                 public bool IsOut {
70                         get {return (AttrsImpl & ParameterAttributes.Out) != 0;}
71                 }
72
73                 public bool IsRetval {
74                         get {return (AttrsImpl & ParameterAttributes.Retval) != 0;}
75                 }
76
77                 public virtual MemberInfo Member {
78                         get {return MemberImpl;}
79                 }
80
81                 public virtual string Name {
82                         get {return NameImpl;}
83                 }
84
85                 public virtual int Position {
86                         get {return PositionImpl;}
87                 }
88
89                 public virtual object[] GetCustomAttributes (bool inherit)
90                 {
91                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
92                 }
93
94                 public virtual object[] GetCustomAttributes (Type attributeType, bool inherit)
95                 {
96                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
97                 }
98
99                 public virtual bool IsDefined( Type attributeType, bool inherit) {
100                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
101                 }
102         }
103 }