1 // System.Reflection.ParameterInfo
4 // Sean MacIsaac (macisaac@ximian.com)
5 // Marek Safar (marek.safar@gmail.com)
7 // (C) 2001 Ximian, Inc.
8 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
9 // Copyright 2013 Xamarin, Inc (http://www.xamarin.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Reflection.Emit;
34 using System.Runtime.CompilerServices;
35 using System.Runtime.InteropServices;
36 using System.Collections.Generic;
38 using System.Runtime.Serialization;
40 namespace System.Reflection
43 [ComDefaultInterfaceAttribute (typeof (_ParameterInfo))]
45 [ClassInterfaceAttribute (ClassInterfaceType.None)]
46 [StructLayout (LayoutKind.Sequential)]
47 public partial class ParameterInfo : ICustomAttributeProvider
55 protected Type ClassImpl;
56 protected object DefaultValueImpl;
57 protected MemberInfo MemberImpl;
58 protected string NameImpl;
59 protected int PositionImpl;
60 protected ParameterAttributes AttrsImpl;
61 internal MarshalAsAttribute marshalAs;
63 protected ParameterInfo () {
66 public override string ToString() {
67 Type elementType = ClassImpl;
68 while (elementType.HasElementType) {
69 elementType = elementType.GetElementType();
71 bool useShort = elementType.IsPrimitive || ClassImpl == typeof(void)
72 || ClassImpl.Namespace == MemberImpl.DeclaringType.Namespace;
73 string result = useShort
76 // MS.NET seems to skip this check and produce an extra space for return types
84 internal static void FormatParameters (StringBuilder sb, ParameterInfo[] p)
86 for (int i = 0; i < p.Length; ++i) {
90 Type pt = p[i].ParameterType;
91 bool byref = pt.IsByRef;
93 pt = pt.GetElementType ();
95 if (Type.ShouldPrintFullName (pt))
96 sb.Append (pt.ToString ());
101 sb.Append (" ByRef");
105 public virtual Type ParameterType {
106 get {return ClassImpl;}
108 public virtual ParameterAttributes Attributes {
109 get {return AttrsImpl;}
114 return (Attributes & ParameterAttributes.In) != 0;
120 return (Attributes & ParameterAttributes.Lcid) != 0;
124 public bool IsOptional {
126 return (Attributes & ParameterAttributes.Optional) != 0;
132 return (Attributes & ParameterAttributes.Out) != 0;
136 public bool IsRetval {
138 return (Attributes & ParameterAttributes.Retval) != 0;
142 public virtual MemberInfo Member {
143 get {return MemberImpl;}
146 public virtual string Name {
147 get {return NameImpl;}
150 public virtual int Position {
151 get {return PositionImpl;}
154 [MethodImplAttribute (MethodImplOptions.InternalCall)]
155 internal extern int GetMetadataToken ();
157 internal object[] GetPseudoCustomAttributes () {
166 if (marshalAs != null)
171 object[] attrs = new object [count];
175 attrs [count ++] = new InAttribute ();
177 attrs [count ++] = new OptionalAttribute ();
179 attrs [count ++] = new OutAttribute ();
181 if (marshalAs != null)
182 attrs [count ++] = marshalAs.Copy ();
187 [MethodImplAttribute (MethodImplOptions.InternalCall)]
188 internal extern Type[] GetTypeModifiers (bool optional);
190 internal object GetDefaultValueImpl ()
192 return DefaultValueImpl;
195 public virtual IEnumerable<CustomAttributeData> CustomAttributes {
196 get { return GetCustomAttributesData (); }
199 public virtual bool HasDefaultValue {
200 get { throw new NotImplementedException (); }
204 void _ParameterInfo.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
206 throw new NotImplementedException ();
209 void _ParameterInfo.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
211 throw new NotImplementedException ();
214 void _ParameterInfo.GetTypeInfoCount (out uint pcTInfo)
216 throw new NotImplementedException ();
219 void _ParameterInfo.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams,
220 IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
222 throw new NotImplementedException ();
226 public virtual object DefaultValue {
227 get { throw new NotImplementedException (); }
230 public virtual object RawDefaultValue {
231 get { throw new NotImplementedException (); }
234 public virtual int MetadataToken {
235 get { return 0x8000000; }
238 public virtual object[] GetCustomAttributes (bool inherit)
240 return new object [0];
243 public virtual object[] GetCustomAttributes (Type attributeType, bool inherit)
245 return new object [0];
248 public object GetRealObject (StreamingContext context)
250 throw new NotImplementedException ();
253 public virtual bool IsDefined( Type attributeType, bool inherit) {
257 public virtual Type[] GetRequiredCustomModifiers () {
261 public virtual Type[] GetOptionalCustomModifiers () {
265 public virtual IList<CustomAttributeData> GetCustomAttributesData () {
266 throw new NotImplementedException ();
269 #if !FULL_AOT_RUNTIME
270 internal static ParameterInfo New (ParameterBuilder pb, Type type, MemberInfo member, int position)
272 return new MonoParameterInfo (pb, type, member, position);
276 internal static ParameterInfo New (ParameterInfo pinfo, Type type, MemberInfo member, int position)
278 return new MonoParameterInfo (pinfo, type, member, position);
281 internal static ParameterInfo New (ParameterInfo pinfo, MemberInfo member)
283 return new MonoParameterInfo (pinfo, member);
286 internal static ParameterInfo New (Type type, MemberInfo member, MarshalAsAttribute marshalAs)
288 return new MonoParameterInfo (type, member, marshalAs);