实施修复列表的预定值的最佳方法是什么?
我正在处理.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用初始化器使用静态读取的自动质体:
用法::
在C#6之前,实现需要更多的详细代码,如说明在这里。
You could use a static read-only auto-property with an initializer:
Usage::
Before C# 6, the implementation required much more verbose code as explaoned here.
从建筑点来看,由于无法确定潜在的变化/痛点和测试要求而没有更好的领域知识,因此很难讨论。
通常,您的apporoach看起来不错,我个人会使用启动器使用ReadOnly Auto-Property,并带有不变的收集接口,例如
ireadonlylist
: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
: