mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 00:08:05 -04:00
Cache and reuse built-in project assemblies instead of recompiling on every editor startup, saving +10s on my machine. (disabled for non-retail builds)
30 lines
732 B
C#
30 lines
732 B
C#
using Mono.Cecil;
|
|
using System.IO;
|
|
|
|
namespace Sandbox;
|
|
|
|
public static class AssemblyMetadata
|
|
{
|
|
public struct Attribute
|
|
{
|
|
public string AttributeType { get; }
|
|
public string AttributeFullName { get; }
|
|
public object[] Arguments { get; }
|
|
|
|
public Attribute( CustomAttribute x )
|
|
{
|
|
AttributeType = x.AttributeType.Name;
|
|
AttributeFullName = x.AttributeType.FullName;
|
|
Arguments = x.ConstructorArguments.Select( a => a.Value ).ToArray();
|
|
}
|
|
}
|
|
|
|
public static Attribute[] GetCustomAttributes( byte[] assemblyData )
|
|
{
|
|
using var ms = new MemoryStream( assemblyData );
|
|
using var assembly = AssemblyDefinition.ReadAssembly( ms );
|
|
|
|
return assembly.CustomAttributes.Select( x => new Attribute( x ) ).ToArray();
|
|
}
|
|
}
|