S&box Wiki

Revision Difference

TypeLibrary#548363

<cat>Code.Misc</cat> <title>TypeLibrary</title> # TypeLibrary TypeLibrary is the replacement for System.Reflection - it'll only let you access types you should have access to within your game. This example should really show you everything you need to know: ```csharp var entName = "BouncyBall"; // Getting a type that matches the name var entityType = TypeLibrary.GetDescription<Entity>( entName )?.TargetType; var entityType = TypeLibrary.GetType<Entity>( entName )?.TargetType; if ( entityType == null ) return; // Checking if that type has the SpawnableAttribute on it if ( !TypeLibrary.Has<SpawnableAttribute>( entityType ) ) if ( !TypeLibrary.HasAttribute<SpawnableAttribute>( entityType ) ) return; // Creating an instance of that type var ent = TypeLibrary.Create<Entity>( entityType ); ```