summaryrefslogtreecommitdiff
path: root/tests/src/baseservices/compilerservices/modulector/runmoduleconstructor.cs
blob: d1192f167a3d613642765983e31867ed48db427f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
using System;
using System.Reflection;
using System.IO;
using System.Runtime.Loader;
using System.Runtime.CompilerServices;
using System.Globalization;

class RuntimeHelperTest 
{
    public static int Main(string[] args)
    {
        AssemblyLoadContext resolver0 = AssemblyLoadContext.Default;
        Assembly asm0 = resolver0.LoadFromAssemblyName(new AssemblyName("moduleCctor"));
        Module mod = asm0.ManifestModule;
        
        RuntimeHelpers.RunModuleConstructor(mod.ModuleHandle);
        var oType   = asm0.GetType("IntHolder",true);
        MethodInfo check = oType.GetMethod("Check");
        MethodInfo assign = oType.GetMethod("Assign");

        object[] initial = {1};
        object[] final   = {100};

        check.Invoke(null, initial);    
        assign.Invoke(null, final);    
        check.Invoke(null, final);    
        RuntimeHelpers.RunModuleConstructor(mod.ModuleHandle);
        check.Invoke(null, final);    

            
        return 100;

    }
}