Skip to content

Commit 6a994bb

Browse files
Added stack trace helper
1 parent 99bd936 commit 6a994bb

File tree

6 files changed

+449
-9
lines changed

6 files changed

+449
-9
lines changed

src/Reflector/IsAssembly.cs

+54
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,58 @@ public static class IsAssembly
1313
{
1414
return Convert.ToString(assembly?.GetName().Version, CultureInfo.InvariantCulture);
1515
}
16+
public static string? GetAssemblyFullName(Assembly assembly)
17+
{
18+
return assembly?.FullName;
19+
}
20+
public static string? GetAssemblyLocation(Assembly assembly)
21+
{
22+
return assembly?.Location;
23+
}
24+
public static string? GetAssemblyCulture(Assembly assembly)
25+
{
26+
return assembly?.GetName().CultureInfo?.Name;
27+
}
28+
public static string? GetAssemblyPublicKeyToken(Assembly assembly)
29+
{
30+
var publicKeyToken = assembly?.GetName().GetPublicKeyToken();
31+
return publicKeyToken != null ? BitConverter.ToString(publicKeyToken).Replace("-", string.Empty) : null;
32+
}
33+
public static IEnumerable<Attribute> GetAssemblyCustomAttributes(Assembly assembly)
34+
{
35+
return assembly?.GetCustomAttributes() ?? Enumerable.Empty<Attribute>();
36+
}
37+
public static bool IsAssemblyFullyTrusted(Assembly assembly)
38+
{
39+
return assembly?.IsFullyTrusted ?? false;
40+
}
41+
public static Type[] GetAssemblyTypes(Assembly assembly)
42+
{
43+
return assembly?.GetTypes() ?? Array.Empty<Type>();
44+
}
45+
public static MethodInfo? GetAssemblyEntryPoint(Assembly assembly)
46+
{
47+
return assembly?.EntryPoint;
48+
}
49+
public static Dictionary<string, string?> GetAssemblyMetadata(Assembly assembly)
50+
{
51+
if (assembly == null)
52+
return new Dictionary<string, string?>();
53+
54+
var metadata = new Dictionary<string, string?>()
55+
{
56+
{ "Name", assembly.GetName().Name },
57+
{ "Version", Convert.ToString(assembly.GetName().Version, CultureInfo.InvariantCulture) },
58+
{ "Culture", assembly.GetName().CultureInfo?.Name },
59+
{ "PublicKeyToken", GetAssemblyPublicKeyToken(assembly) },
60+
{ "Location", assembly.Location }
61+
};
62+
63+
return metadata;
64+
}
65+
public static string[] GetAssemblyManifestResourceNames(Assembly assembly)
66+
{
67+
return assembly?.GetManifestResourceNames() ?? Array.Empty<string>();
68+
}
69+
1670
}

src/Reflector/IsMemory.cs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.Text;
2+
3+
namespace VReflector;
4+
5+
public static class IsMemory
6+
{
7+
public static long GetMemoryUsage(bool forceFullCollection = false)
8+
{
9+
if (forceFullCollection)
10+
{
11+
GC.Collect();
12+
GC.WaitForPendingFinalizers();
13+
GC.Collect();
14+
}
15+
return GC.GetTotalMemory(forceFullCollection);
16+
}
17+
18+
public static long GetHeapSize()
19+
{
20+
var gcInfo = GC.GetGCMemoryInfo();
21+
return gcInfo.HeapSizeBytes;
22+
}
23+
24+
public static double GetGCFragmentation()
25+
{
26+
var gcInfo = GC.GetGCMemoryInfo();
27+
return (double)gcInfo.FragmentedBytes / gcInfo.HeapSizeBytes;
28+
}
29+
30+
public static long GetAllocatedMemoryForCurrentThread()
31+
{
32+
return GC.GetAllocatedBytesForCurrentThread();
33+
}
34+
35+
public static long GetTotalAllocatedMemory()
36+
{
37+
return GC.GetTotalAllocatedBytes();
38+
}
39+
40+
public static string GetMemoryUsageDetails()
41+
{
42+
var gcInfo = GC.GetGCMemoryInfo();
43+
var sb = new StringBuilder();
44+
45+
sb.AppendLine($"Heap Size: {gcInfo.HeapSizeBytes} bytes");
46+
sb.AppendLine($"Fragmented Bytes: {gcInfo.FragmentedBytes} bytes");
47+
sb.AppendLine($"Memory Usage: {GC.GetTotalMemory(false)} bytes");
48+
49+
return sb.ToString();
50+
}
51+
}

0 commit comments

Comments
 (0)