1 // System.Reflection.ParameterInfo
3 // Sean MacIsaac (macisaac@ximian.com)
5 // (C) 2001 Ximian, Inc.
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System
.Reflection
.Emit
;
31 using System
.Runtime
.CompilerServices
;
32 using System
.Runtime
.InteropServices
;
34 namespace System
.Reflection
37 public class ParameterInfo
: ICustomAttributeProvider
39 protected Type ClassImpl
;
40 protected object DefaultValueImpl
;
41 protected MemberInfo MemberImpl
;
42 protected string NameImpl
;
43 protected int PositionImpl
;
44 protected ParameterAttributes AttrsImpl
;
45 private UnmanagedMarshal marshalAs
;
47 protected ParameterInfo () {
50 internal ParameterInfo (ParameterBuilder pb
, Type type
, MemberInfo member
, int position
) {
51 this.ClassImpl
= type
;
52 this.MemberImpl
= member
;
54 this.NameImpl
= pb
.Name
;
55 this.PositionImpl
= pb
.Position
- 1; // ParameterInfo.Position is zero-based
56 this.AttrsImpl
= (ParameterAttributes
) pb
.Attributes
;
59 this.PositionImpl
= position
- 1;
60 this.AttrsImpl
= ParameterAttributes
.None
;
64 /* to build a ParameterInfo for the return type of a method */
65 internal ParameterInfo (Type type
, MemberInfo member
) {
66 this.ClassImpl
= type
;
67 this.MemberImpl
= member
;
69 this.PositionImpl
= -1; // since parameter positions are zero-based, return type pos is -1
70 this.AttrsImpl
= ParameterAttributes
.Retval
;
73 public virtual Type ParameterType
{
74 get {return ClassImpl;}
76 public virtual ParameterAttributes Attributes
{
77 get {return AttrsImpl;}
79 public virtual object DefaultValue
{
80 get {return DefaultValueImpl;}
84 get {return (AttrsImpl & ParameterAttributes.In) != 0;}
88 get {return (AttrsImpl & ParameterAttributes.Lcid) != 0;}
91 public bool IsOptional
{
92 get {return (AttrsImpl & ParameterAttributes.Optional) != 0;}
96 get {return (AttrsImpl & ParameterAttributes.Out) != 0;}
99 public bool IsRetval
{
100 get {return (AttrsImpl & ParameterAttributes.Retval) != 0;}
103 public virtual MemberInfo Member
{
104 get {return MemberImpl;}
107 public virtual string Name
{
108 get {return NameImpl;}
111 public virtual int Position
{
112 get {return PositionImpl;}
115 #if NET_2_0 || BOOTSTRAP_NET_2_0
120 virtual extern int MetadataToken
{
121 [MethodImplAttribute (MethodImplOptions
.InternalCall
)]
125 public virtual object[] GetCustomAttributes (bool inherit
)
127 return MonoCustomAttrs
.GetCustomAttributes (this, inherit
);
130 public virtual object[] GetCustomAttributes (Type attributeType
, bool inherit
)
132 return MonoCustomAttrs
.GetCustomAttributes (this, attributeType
, inherit
);
135 public virtual bool IsDefined( Type attributeType
, bool inherit
) {
136 return MonoCustomAttrs
.IsDefined (this, attributeType
, inherit
);
139 internal object[] GetPseudoCustomAttributes () {
148 if (marshalAs
!= null)
153 object[] attrs
= new object [count
];
157 attrs
[count
++] = new InAttribute ();
159 attrs
[count
++] = new OptionalAttribute ();
161 attrs
[count
++] = new OutAttribute ();
163 if (marshalAs
!= null)
164 attrs
[count
++] = marshalAs
.ToMarshalAsAttribute ();
169 #if NET_2_0 || BOOTSTRAP_NET_2_0
171 public virtual Type
[] OptionalCustomModifiers
{
173 throw new NotImplementedException ();
178 public virtual Type
[] RequiredCustomModifiers
{
180 throw new NotImplementedException ();