public void CreateMethodBody( byte[] il, int count) {
if ((il != null) && ((count < 0) || (count > il.Length)))
- throw new ArgumentException ("Index was out of range. Must be non-negative and less than the size of the collection.");
+ throw new ArgumentOutOfRangeException ("Index was out of range. Must be non-negative and less than the size of the collection.");
if ((code != null) || type.is_created)
throw new InvalidOperationException ("Type definition of the method is complete.");
internal void fixup () {
if (((attrs & (MethodAttributes.Abstract | MethodAttributes.PinvokeImpl)) == 0) && ((iattrs & (MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall)) == 0)) {
+#if NET_2_0
+ // do not allow zero length method body on MS.NET 2.0 (and higher)
+ if (((ilgen == null) || (ILGenerator.Mono_GetCurrentOffset (ilgen) == 0)) && (code == null || code.Length == 0))
+#else
if (((ilgen == null) || (ILGenerator.Mono_GetCurrentOffset (ilgen) == 0)) && (code == null))
+#endif
throw new InvalidOperationException ("Method '" + Name + "' does not have a method body.");
}
if (ilgen != null)
public void TestMethodHandleComplete () {
MethodBuilder mb = genClass.DefineMethod (
genMethodName (), 0, typeof (void), new Type [0]);
- mb.CreateMethodBody (new byte[2], 0);
+ mb.CreateMethodBody (new byte[2], 1);
genClass.CreateType ();
RuntimeMethodHandle handle = mb.MethodHandle;
try {
mb.CreateMethodBody (new byte[1], -1);
Fail ();
- } catch (ArgumentException) {
+ } catch (ArgumentOutOfRangeException) {
}
// Check arguments 2.
try {
mb.CreateMethodBody (new byte[1], 2);
Fail ();
- } catch (ArgumentException) {
+ } catch (ArgumentOutOfRangeException) {
}
mb.CreateMethodBody (new byte[2], 1);
new Type[2] {
typeof(int), typeof(int)
});
- mb.CreateMethodBody (new byte[2], 0);
+ mb.CreateMethodBody (new byte[2], 1);
tb.CreateType ();
mb.DefineParameter (-5, ParameterAttributes.None, "param1");
}
new Type[2] {
typeof(int), typeof(int)
});
- mb.CreateMethodBody (new byte[2], 0);
+ mb.CreateMethodBody (new byte[2], 1);
tb.CreateType ();
mb.DefineParameter (1, ParameterAttributes.None, "param1");
}
mb.DefineParameter (1, 0, "param1");
mb.DefineParameter (2, 0, null);
- // Can not be called on a created type
- mb.CreateMethodBody (new byte[2], 0);
+ mb.CreateMethodBody (new byte[2], 1);
tb.CreateType ();
try {
mb.DefineParameter (1, 0, "param1");
}
}
+ [Test]
+#if NET_2_0
+ // MS.NET 2.x no longer allows a zero length method body
+ // to be emitted
+ [ExpectedException (typeof (InvalidOperationException))]
+#endif
+ public void ZeroLengthBodyTest1 ()
+ {
+ MethodBuilder mb = genClass.DefineMethod (
+ genMethodName (), 0, typeof (void),
+ new Type [2] { typeof(int), typeof(int) });
+ mb.CreateMethodBody (new byte[2], 0);
+ genClass.CreateType ();
+ }
+
+ // A zero length method body can be created
+ [Test]
+ public void ZeroLengthBodyTest2 ()
+ {
+ MethodBuilder mb = genClass.DefineMethod (
+ genMethodName (), 0, typeof (void),
+ new Type [2] { typeof(int), typeof(int) });
+ mb.CreateMethodBody (new byte[2], 0);
+ }
+
[Test]
public void TestHashCode ()
{
MethodImplAttributes.OPTIL,
mb.GetMethodImplementationFlags ());
- // Can not be called on a created type
- mb.CreateMethodBody (new byte[2], 0);
+ mb.CreateMethodBody (new byte[2], 1);
mb.SetImplementationFlags (MethodImplAttributes.Managed);
tb.CreateType ();
try {