mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-06 13:28:32 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
30 lines
998 B
C#
30 lines
998 B
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace Sandbox;
|
|
|
|
/// <summary>
|
|
/// Interface for objects that can become invalid over time,
|
|
/// such as references to deleted game objects or disposed resources.
|
|
/// </summary>
|
|
public interface IValid
|
|
{
|
|
/// <summary>
|
|
/// Returns true if this object is still valid and can be safely accessed.
|
|
/// When false, accessing the object's properties or methods may throw exceptions.
|
|
/// </summary>
|
|
bool IsValid { get; }
|
|
}
|
|
|
|
public static partial class SandboxSystemExtensions
|
|
{
|
|
/// <summary>
|
|
/// Returns false if <see cref="IValid"/> object is null or if <see cref="IValid.IsValid"/> returns false.
|
|
/// </summary>
|
|
#nullable enable
|
|
[Pure, ActionGraphNode( "sys.isvalid" ), Icon( "assignment_turned_in" ), Category( "Object:data_object" )]
|
|
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
|
public static bool IsValid( [NotNullWhen( true )] this IValid? obj ) => obj != null && obj.IsValid;
|
|
#nullable restore
|
|
}
|