X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Reflection.Emit%2FParameterBuilder.cs;h=97f998051304136cc366fea080def4168c65dd44;hb=863ddf25bfb4e88db7225dd4968a4403840c42af;hp=2832768238a5763903d68b2bda0bdc027e471c08;hpb=2007998771b1c4d9e762943676d7959daaf74385;p=mono.git diff --git a/mcs/class/corlib/System.Reflection.Emit/ParameterBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/ParameterBuilder.cs index 2832768238a..97f99805130 100644 --- a/mcs/class/corlib/System.Reflection.Emit/ParameterBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/ParameterBuilder.cs @@ -32,6 +32,7 @@ // (C) 2001 Ximian, Inc. http://www.ximian.com // +#if !FULL_AOT_RUNTIME using System; using System.Reflection; using System.Reflection.Emit; @@ -40,12 +41,13 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Reflection.Emit { -#if NET_2_0 [ComVisible (true)] [ComDefaultInterface (typeof (_ParameterBuilder))] -#endif [ClassInterface (ClassInterfaceType.None)] + [StructLayout (LayoutKind.Sequential)] public class ParameterBuilder : _ParameterBuilder { + +#pragma warning disable 169, 414 private MethodBase methodb; /* MethodBuilder, ConstructorBuilder or DynamicMethod */ private string name; private CustomAttributeBuilder[] cattrs; @@ -54,17 +56,16 @@ namespace System.Reflection.Emit { private int position; private int table_idx; object def_value; +#pragma warning restore 169, 414 internal ParameterBuilder (MethodBase mb, int pos, ParameterAttributes attributes, string strParamName) { name = strParamName; position = pos; attrs = attributes; methodb = mb; -#if NET_2_0 if (mb is DynamicMethod) table_idx = 0; else -#endif table_idx = mb.get_next_table_index (this, 0x08, true); } @@ -93,6 +94,16 @@ namespace System.Reflection.Emit { public virtual void SetConstant (object defaultValue) { + if (position > 0) { + Type t = methodb.GetParameterType (position - 1); + if (defaultValue != null && t != defaultValue.GetType ()) { + if(!t.IsEnum || t.UnderlyingSystemType != defaultValue.GetType ()) + throw new ArgumentException ("Constant does not match the defined type."); + } + if (t.IsValueType && !t.IsPrimitive && !t.IsEnum && t != typeof (DateTime)) + throw new ArgumentException ("" + t + " is not a supported constant type."); + } + def_value = defaultValue; attrs |= ParameterAttributes.HasDefault; } @@ -110,7 +121,7 @@ namespace System.Reflection.Emit { return; } else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") { attrs |= ParameterAttributes.HasFieldMarshal; - marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, true); + marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, false); /* FIXME: check for errors */ return; } else if (attrname == "System.Runtime.InteropServices.DefaultParameterValueAttribute") { @@ -132,16 +143,12 @@ namespace System.Reflection.Emit { } } -#if NET_2_0 [ComVisible (true)] -#endif public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) { SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute)); } -#if NET_2_0 [Obsolete ("An alternate API is available: Emit the MarshalAs custom attribute instead.")] -#endif public virtual void SetMarshal( UnmanagedMarshal unmanagedMarshal) { marshal_info = unmanagedMarshal; attrs |= ParameterAttributes.HasFieldMarshal; @@ -169,3 +176,4 @@ namespace System.Reflection.Emit { } } +#endif