Files
sbox-public/engine/Sandbox.System/Utility/IValid.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

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
}