// (C) 2001 Ximian, Inc. http://www.ximian.com
//
+#if !FULL_AOT_RUNTIME
using System;
using System.Reflection;
using System.Reflection.Emit;
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;
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);
}
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;
}
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") {
}
}
-#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;
}
}
+#endif