-1

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();
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
K.Z
  • 5,201
  • 25
  • 104
  • 240

2 Answers2

0

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.

mm8
  • 163,881
  • 10
  • 57
  • 88
-1

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 [] { ".", ".." };
}
Guru Stron
  • 102,774
  • 10
  • 95
  • 132