[runtime] Synthesize IList and IReadOnlyList for the element type of enum errays...
[mono.git] / mono / tests / bug-47295.cs
1 //
2 //  bug-47295.cs:
3 //
4 //    Regression test for bug #47295.
5 //
6 //  Test from Marcus Urban (mathpup@mylinuxisp.com)
7 //   
8
9 using System; 
10 using System.Reflection; 
11 using System.Reflection.Emit; 
12 using System.Runtime.InteropServices; 
13  
14  
15 public class Testing 
16
17     public static void Method(int value) 
18     { 
19         Console.WriteLine( "Method( {0} )", value ); 
20     } 
21  
22  
23     [StructLayout(LayoutKind.Sequential)] 
24     internal struct DelegateList 
25     { 
26         internal Delegate del; 
27     } 
28  
29  
30     public static void Main() 
31     { 
32         // Create a dynamic assembly and module to contain the 
33         // subclass of MulticastDelegate that we will create 
34  
35         AssemblyName asmName = new AssemblyName(); 
36         asmName.Name = "DynamicAssembly"; 
37  
38         AssemblyBuilder asmBuilder = 
39             AppDomain.CurrentDomain.DefineDynamicAssembly( 
40                 asmName, AssemblyBuilderAccess.Run ); 
41  
42         ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
43 ( "DynamicModule" ); 
44  
45         TypeBuilder typeBuilder = modBuilder.DefineType( "MyType", 
46             TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed, 
47             typeof( System.MulticastDelegate ) ); 
48  
49         ConstructorBuilder cb = typeBuilder.DefineConstructor( 
50             MethodAttributes.Public | MethodAttributes.HideBySig | 
51             MethodAttributes.RTSpecialName | MethodAttributes.SpecialName, 
52             CallingConventions.Standard, 
53             new Type[] { typeof(Object), typeof (IntPtr) } ); 
54  
55         cb.SetImplementationFlags( MethodImplAttributes.Runtime | 
56 MethodImplAttributes.Managed ); 
57  
58         MethodBuilder mb = typeBuilder.DefineMethod( 
59             "Invoke", 
60             MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.
61 HideBySig, 
62             typeof(void), 
63             new Type[] { typeof(int) } ); 
64  
65         mb.SetImplementationFlags( MethodImplAttributes.Runtime | 
66 MethodImplAttributes.Managed ); 
67                 ParameterBuilder pb = mb.DefineParameter (1, ParameterAttributes.HasFieldMarshal, "foo");
68                 pb.SetMarshal (UnmanagedMarshal.DefineUnmanagedMarshal (UnmanagedType.I2));
69  
70         // Create an instance of the delegate type and invoke it -- just to test 
71  
72         Type myDelegateType = typeBuilder.CreateType(); 
73         Delegate d = Delegate.CreateDelegate( myDelegateType, typeof
74 ( Testing ), "Method" ); 
75         d.DynamicInvoke( new object[] { 8 } );
76  
77         DelegateList delegateList = new DelegateList(); 
78         delegateList.del = d; 
79         IntPtr ptr = Marshal.AllocHGlobal( Marshal.SizeOf( delegateList ) ); 
80  
81         // The execption seems to occur at this statement: 
82         Marshal.StructureToPtr( delegateList, ptr, false ); 
83     } 
84  
85