Code/PanelTypeReference.cs

A small helper class that stores a panel type name and resolves it to a TypeDescription using the engine TypeLibrary. It first tries GetType(TypeName) then falls back to searching GetTypes() for a matching TargetType.FullName.

using Sandbox;
using System.Linq;

namespace PanelRenderTarget;

//class used for autoreflection of panel
public sealed class PanelTypeReference
{
	public string TypeName { get; set; }

	public TypeDescription Resolve()
	{
		if ( string.IsNullOrWhiteSpace( TypeName ) )
			return null;

		return Game.TypeLibrary?.GetType( TypeName )
			?? Game.TypeLibrary?.GetTypes()
				.FirstOrDefault( x => x.TargetType?.FullName == TypeName );
	}
}