Skip to content

Commit df5bd31

Browse files
committed
Reworking the logic to use reflection to invoke the profile. This removes any conditional compilation
1 parent f8977c7 commit df5bd31

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

src/ScriptCs/Program.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Reflection;
34
using System.Runtime;
45
using ScriptCs.Argument;
56
using ScriptCs.Command;
@@ -13,15 +14,7 @@ internal static class Program
1314
{
1415
private static int Main(string[] args)
1516
{
16-
#if !__MonoCS__
17-
try
18-
{
19-
SetProfile();
20-
}
21-
catch (TypeLoadException)
22-
{
23-
}
24-
#endif
17+
SetProfile();
2518

2619
IConsole console = new ScriptConsole();
2720

@@ -93,16 +86,17 @@ private static string[] GetModuleList(string modulesArg)
9386
return modules;
9487
}
9588

96-
#if !__MonoCS__
97-
[MethodImpl(MethodImplOptions.NoInlining)]
9889
private static void SetProfile()
9990
{
100-
if (Type.GetType("Mono.Runtime") == null)
91+
var profileOptimizationType = Type.GetType("System.Runtime.ProfileOptimization");
92+
if (profileOptimizationType != null)
10193
{
102-
ProfileOptimization.SetProfileRoot(typeof(Program).Assembly.Location);
103-
ProfileOptimization.StartProfile(typeof(Program).Assembly.GetName().Name + ".profile");
94+
var setProfileRoot = profileOptimizationType.GetMethod("SetProfileRoot", BindingFlags.Public | BindingFlags.Static);
95+
setProfileRoot.Invoke(null, new object[] {typeof (Program).Assembly.Location});
96+
97+
var startProfile = profileOptimizationType.GetMethod("StartProfile", BindingFlags.Public | BindingFlags.Static);
98+
startProfile.Invoke(null, new object[] {typeof (Program).Assembly.GetName().Name + ".profile"});
10499
}
105100
}
106-
#endif
107101
}
108102
}

0 commit comments

Comments
 (0)