I have a method and I am trying to add another method as a list variable so that I can add multiple Error’s per file. I am currently passing the files list variable to multiple different functions. I would like the Error variable to be contained in the files, but I have been unable to figure it out. Thanks!
class AllFiles
{
public string FileName { get; set; }
public string FileType { get; set; }
...
public List<ErrorClass> Error { get; set; }
}
class ErrorClass
{
public int ErrorCode { get; set; }
public int Total { get; set; }
public string ErrorMessage { get; set; }
...
}
I use the following to initialize my files as a list so I can add multiple files.
List<AllFiles> files = new List<AllFiles>();
files.Add(new AllFiles());
I am wanting it to look like the following:
files[0]
Error[0]
Error[1]
files[1]
Error[0]
Error[1]
Error[2]
files[2]
Error[0]
...
You need to create an instance of the
List<ErrorClass>(ideally) inside theAllFilesclass’ constructor, and assign it to theErrorproperty.Some other recommendations:
AllFilesis not a good name for a class that represents one fileErrorClasscould maybe just be calledErrororFileErrorErrorproperty insideAllFilesshould be namedErrorsand should have a private setter.E.g.:
Depending on your design, you could better encapsulate the error list inside
MyFileand just expose anIEnumerable<MyFileError>and anAddError(MyFileError)method.