Files
GhostEngine/Ghost.Core/Result.cs
Misaki a8d7cd8828 Refactor and enhance rendering pipeline
- Added new C# formatting rules in .editorconfig.
- Introduced `IKeyType`, `Key<T>`, and `Ptr<T>` structs.
- Updated `Result` and `Result<T>` for implicit conversions.
- Added AOT compatibility to project files.
- Introduced a `Camera` class and refactored namespaces.
- Enhanced rendering with bindless support and pipeline state management.
- Refactored `D3D12CommandBuffer` for new rendering features.
- Improved `D3D12PipelineLibrary` with disk caching methods.
- Added support for UAVs and raw buffers in `D3D12ResourceAllocator`.
- Improved shader compilation and reflection in `D3D12ShaderCompiler`.
- Refactored descriptor heap and swap chain initialization.
- Added enums and structs for rendering configurations.
- Expanded `ICommandBuffer` and `IPipelineLibrary` interfaces.
- Updated `MeshRenderPass` to align with the new pipeline.
- Consolidated namespaces and improved code maintainability.
2025-11-01 22:30:08 +09:00

80 lines
1.9 KiB
C#

namespace Ghost.Core;
public readonly struct Result
{
public readonly bool success;
public readonly string? message;
public Result(bool success, string? message = null)
{
this.success = success;
this.message = message;
}
public static Result Success()
{
return new Result(true);
}
public static Result Fail(string? message)
{
return new Result(false, message);
}
public override string ToString() => success ? "OK" : $"Error: {message}";
public static implicit operator bool(Result result) => result.success;
}
public readonly struct Result<T>
{
public readonly bool success;
public readonly T value;
public readonly string? message;
public Result(bool success, T data, string? message = null)
{
this.success = success;
this.value = data;
this.message = message;
}
public static Result<T> Success(T data)
{
return new Result<T>(true, data);
}
public static Result<T> Fail(string? message)
{
return new Result<T>(false, default!, message);
}
public override string ToString() => success ? $"OK: {value}" : $"Error: {message}";
public static implicit operator Result<T>(T? data) => data is not null ? Success(data) : Fail(null);
public static implicit operator Result<T>(Result result) => result.success ? Success(default!) : Fail(result.message);
}
public static class ResultExtensions
{
public static void ThrowIfFailed(this Result result)
{
if (!result.success)
{
throw new InvalidOperationException($"Operation failed: {result.message}");
}
}
public static T GetValueOrThrow<T>(this Result<T> result)
{
if (!result.success)
{
throw new InvalidOperationException($"Operation failed: {result.message}");
}
return result.value;
}
}