Files
Pal3.Unity/Assets/Scripts/Pal3.Core/Utilities/Requires.cs
Jiaqi (0x7c13) Liu e870cf487a Add core protocol regression tests and copyright checks
Cover SCE command contracts, binary readers, resource layouts and full local CPK decompression for PAL3 and PAL3A. Fix CVD time rebasing, binary read bounds and short reads, and CPK/NAV validation.

Standardize first-party copyright headers, preserve correct creation years, and update console source generation. Validate both variants in Unity and verify all live CPK entries.
2026-11-12 13:37:27 +08:00

72 lines
2.1 KiB
C#

// ------------------------------------------------------------------------
// Copyright (c) 2021-2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Core.Utilities
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
/// <summary>
/// Checks method arguments for both dotnet objects and Unity objects.
/// </summary>
public static class Requires
{
public static T IsNotNull<T>([NotNull] T instance, string paramName)
where T : class
{
if (typeof(T) == typeof(object) ||
typeof(T).IsSubclassOf(typeof(object)))
{
if (ReferenceEquals(null, instance))
{
throw new ArgumentNullException(paramName);
}
}
else if (instance == null)
{
throw new ArgumentNullException(paramName);
}
return instance;
}
public static string IsNotNullOrEmpty([NotNull] string value, string paramName)
{
IsNotNull(value, paramName);
if (value == string.Empty)
{
throw new ArgumentException(paramName);
}
return value;
}
public static ICollection<T> IsNotNullOrEmpty<T>([NotNull] ICollection<T> value, string paramName)
{
IsNotNull(value, paramName);
if (value.Count == 0)
{
throw new ArgumentException("Collection is empty", paramName);
}
return value;
}
public static T[] IsNotNullOrEmpty<T>([NotNull] T[] instances, string paramName)
{
IsNotNull(instances, paramName);
if (instances.Length == 0)
{
throw new ArgumentException("Array is empty", paramName);
}
return instances;
}
}
}