实施修复列表的预定值的最佳方法是什么?

发布于 2025-01-27 08:49:31 字数 542 浏览 1 评论 0原文

我正在处理.NET CORE 6 Renci.sshnet库。当我使用sftpclient.listdirectory读取文件时,我也会阅读& ..作为文件。我想创建仅处理此列表的const外部服务类列表。我想从体系结构的角度了解最佳方法,即使用const,value对象,构造或可读性,

我设法将原型拉开,

public static class RejectedFileName
{
    private static readonly string[] FileNames = {".", ".."};

    public static string[] GetNames()
    {
        return FileNames;
    }
}

因为我可以在我的服务类中使用作为

var filteredFiles = files.Except(RejectedFileName.GetNames()).ToList();

I am working on .NET CORE 6 Renci.SshNet library. When I read files using SftpClient.ListDirectory I also read . & .. as files. I want to create list of const outside service class that just deal with this list. I want to know best approach from architecture point of view i.e. using const, value object, struct, or readonly

I have manage to pull the prototype as

public static class RejectedFileName
{
    private static readonly string[] FileNames = {".", ".."};

    public static string[] GetNames()
    {
        return FileNames;
    }
}

then I can use in my service class as

var filteredFiles = files.Except(RejectedFileName.GetNames()).ToList();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜妞爱困 2025-02-03 08:49:31

您可以使用初始化器使用静态读取的自动质体:

public static class Rejected
{
    public static string[] FileNames { get; }
        = { ".", ".." };
}

用法:

var filteredFiles = files.Except(Rejected.FileNames).ToList();

在C#6之前,实现需要更多的详细代码,如说明在这里

You could use a static read-only auto-property with an initializer:

public static class Rejected
{
    public static string[] FileNames { get; }
        = { ".", ".." };
}

Usage::

var filteredFiles = files.Except(Rejected.FileNames).ToList();

Before C# 6, the implementation required much more verbose code as explaoned here.

淡莣 2025-02-03 08:49:31

从建筑点来看,由于无法确定潜在的变化/痛点和测试要求而没有更好的领域知识,因此很难讨论。

通常,您的apporoach看起来不错,我个人会使用启动器使用ReadOnly Auto-Property,并带有不变的收集接口,例如 ireadonlylist

public static class Rejected
{
    public static IReadOnlyList<string> FileNames { get; } = new [] { ".", ".." };
}

From architecture point it is hard to discuss due to inability to determine potential change/pain points and testing requirements without better domain knowledge.

In general your apporoach seems fine, personally I would use a readonly auto-property with initializer and typed with immutable collection interface, for example IReadOnlyList:

public static class Rejected
{
    public static IReadOnlyList<string> FileNames { get; } = new [] { ".", ".." };
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文