2009-12-02 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / System.Reflection.Emit / ParameterBuilder.cs
blobd76073f45ad104a4dcd8fa6d63ec8728af126471
2 //
3 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 // System.Reflection.Emit/ParameterBuilder.cs
29 // Author:
30 // Paolo Molaro (lupus@ximian.com)
32 // (C) 2001 Ximian, Inc. http://www.ximian.com
35 using System;
36 using System.Reflection;
37 using System.Reflection.Emit;
38 using System.Globalization;
39 using System.Runtime.CompilerServices;
40 using System.Runtime.InteropServices;
42 namespace System.Reflection.Emit {
43 [ComVisible (true)]
44 [ComDefaultInterface (typeof (_ParameterBuilder))]
45 [ClassInterface (ClassInterfaceType.None)]
46 public class ParameterBuilder : _ParameterBuilder {
48 #pragma warning disable 169, 414
49 private MethodBase methodb; /* MethodBuilder, ConstructorBuilder or DynamicMethod */
50 private string name;
51 private CustomAttributeBuilder[] cattrs;
52 private UnmanagedMarshal marshal_info;
53 private ParameterAttributes attrs;
54 private int position;
55 private int table_idx;
56 object def_value;
57 #pragma warning restore 169, 414
59 internal ParameterBuilder (MethodBase mb, int pos, ParameterAttributes attributes, string strParamName) {
60 name = strParamName;
61 position = pos;
62 attrs = attributes;
63 methodb = mb;
64 if (mb is DynamicMethod)
65 table_idx = 0;
66 else
67 table_idx = mb.get_next_table_index (this, 0x08, true);
70 public virtual int Attributes {
71 get {return (int)attrs;}
73 public bool IsIn {
74 get {return ((int)attrs & (int)ParameterAttributes.In) != 0;}
76 public bool IsOut {
77 get {return ((int)attrs & (int)ParameterAttributes.Out) != 0;}
79 public bool IsOptional {
80 get {return ((int)attrs & (int)ParameterAttributes.Optional) != 0;}
82 public virtual string Name {
83 get {return name;}
85 public virtual int Position {
86 get {return position;}
89 public virtual ParameterToken GetToken() {
90 return new ParameterToken (0x08 | table_idx);
93 public virtual void SetConstant (object defaultValue)
95 def_value = defaultValue;
96 attrs |= ParameterAttributes.HasDefault;
99 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
100 string attrname = customBuilder.Ctor.ReflectedType.FullName;
101 if (attrname == "System.Runtime.InteropServices.InAttribute") {
102 attrs |= ParameterAttributes.In;
103 return;
104 } else if (attrname == "System.Runtime.InteropServices.OutAttribute") {
105 attrs |= ParameterAttributes.Out;
106 return;
107 } else if (attrname == "System.Runtime.InteropServices.OptionalAttribute") {
108 attrs |= ParameterAttributes.Optional;
109 return;
110 } else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
111 attrs |= ParameterAttributes.HasFieldMarshal;
112 marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, false);
113 /* FIXME: check for errors */
114 return;
115 } else if (attrname == "System.Runtime.InteropServices.DefaultParameterValueAttribute") {
116 /* MS.NET doesn't handle this attribute but we handle it for consistency */
117 CustomAttributeBuilder.CustomAttributeInfo cinfo = CustomAttributeBuilder.decode_cattr (customBuilder);
118 /* FIXME: check for type compatibility */
119 SetConstant (cinfo.ctorArgs [0]);
120 return;
123 if (cattrs != null) {
124 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
125 cattrs.CopyTo (new_array, 0);
126 new_array [cattrs.Length] = customBuilder;
127 cattrs = new_array;
128 } else {
129 cattrs = new CustomAttributeBuilder [1];
130 cattrs [0] = customBuilder;
134 [ComVisible (true)]
135 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
136 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
139 [Obsolete ("An alternate API is available: Emit the MarshalAs custom attribute instead.")]
140 public virtual void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
141 marshal_info = unmanagedMarshal;
142 attrs |= ParameterAttributes.HasFieldMarshal;
145 void _ParameterBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
147 throw new NotImplementedException ();
150 void _ParameterBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
152 throw new NotImplementedException ();
155 void _ParameterBuilder.GetTypeInfoCount (out uint pcTInfo)
157 throw new NotImplementedException ();
160 void _ParameterBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
162 throw new NotImplementedException ();