Using static class to return folders and files for particular objects, should I just return string or FileInfo/DirInfo? How to use :this() with constructor?

Question1) I'm created a bunch of extension methods in a static class to return files/folders. They do an exists check and create the file/folder if it fails. I've always simply returned a string with the fullpath. But I was trying to plan of future and started return FileInfo/DirInfo objects. Is this a waste? Presently, I'm only using this methods to read/write files with the static File/Directory class's Read/Write-AllLines() method when I get the FileInfo from my static class. Now I'm thinking it's just sillly to create fileinfo and then only use the FileInfoObj.FullName. What would be a good plan?

Q2) I have another static class that I use to add exntensions and lists for my EntityModel objects. If I use some entity a lot and the data in the Db isn't a lot, I'll just add a static list to this class that stores that data in memory.

Now I were to create a constructor public EntityObject(EntityObject givenEntityObject) : this() { }

will that just create a new instance of the same object?

Now if I want another constructor like

 public EntityObject(string Name) { //how can I get this to return to me this objects instance in my StaticListOfObjects with something like if (StaticListOfObjects.Any(x => x.Name == name) { 

//make this object…. that object from the list } else { //actually create this object} }

One way I see is to assign each member with values from staticList's instance of object with this name. But is there a simpler way to do the same?

by pope_says via /r/csharp

Leave a Reply