Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

We need to consider a unified API for validation

未关闭
#37 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@marchc1 已经在做这个了。

开始于 2025年10月15日。

评估

这个 Issue 还没有评估数据。

描述

Enhancement Needs More Info

Right now, a lot of things in the engine (Materials, Textures, Panels, etc) do not have a better way to determine if they're valid or not. While we won't get UAF's for having invalid pointers or anything, we will keep around resources that dont need to be kept, which also can lead to unintended behavior.

My previous engines have had something along the lines of this:

public interface IValidatable : IDisposable 
{
    bool Valid();
}
public static class IValidatableExts
{
    public static bool IsValid<T>(this T? object) where T : IValidatable => object == null ? false : object.Valid();
}

This would allow us to have Panel for example implement it as such:

public class Panel() {
    bool valid = true;
    ...
    void Remove() {
        ...
        Dispose();
        ...
    }
    void Dispose() {
        valid = false;
    }
    bool Valid() => valid;
    ...
}

The nice thing about the extension-based API here is that T can be nullable, which allows us to run this even on a null object - meaning we don't have to do something like obj != null && obj.IsValid() - this is all valid:

Panel? panel = null;
Assert(!panel.IsValid())
panel = new Button(...);
Assert(panel.IsValid())
panel.Remove();
Assert(!panel.IsValid())

It just deviates from what Source does (ie. Source has PHandles, etc). I just think this is a little nicer given we're working with C#.

主要语言
C#
星标
104
派生
9
平均合并
8 小时 52 分钟
30 天内合并 PR
115

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

SourceDotNET/Source.NET 的其他 Issue

查看 SourceDotNET/Source.NET 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。