Skip to content

Commit 057b068

Browse files
committed
Add a helper for avoid and prevent calling methods via reflection for plugins
#7
1 parent 19d4edd commit 057b068

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Diagnostics;
2+
3+
namespace FlowSynx.PluginCore.Helpers;
4+
5+
public static class ReflectionHelper
6+
{
7+
public static bool IsCalledViaReflection()
8+
{
9+
var stack = new StackTrace();
10+
var frames = stack.GetFrames();
11+
12+
if (frames == null)
13+
return false;
14+
15+
foreach (var frame in frames)
16+
{
17+
var callingMethod = frame.GetMethod();
18+
if (callingMethod == null) continue;
19+
20+
if (callingMethod.DeclaringType?.Namespace?.StartsWith("System.Reflection") == true)
21+
return true;
22+
}
23+
24+
return false;
25+
}
26+
}

0 commit comments

Comments
 (0)