私は次のクラスを持っています:
public class FolderAgent
{
public string directoryName {get; private set; }
public int numberofdirectories {get; private set; }
public int numberofFiles {get; private set;}
public DirectoryInfo [] directories {get; private set;}
public FileInfo [] files {get; private set;}
public FolderAgent(string directoryName, int numberofdirectories, int numberofFiles, DirectoryInfo [] listDir, FileInfo [] listFiles)
{
this.directoryName = directoryName;
this.numberofdirectories = numberofdirectories;
this.numberofFiles = numberofFiles;
Array.Copy(listDir, directories, listDir.Length);
Array.Copy(listFiles, files, listFiles.Length);
}
}
コンストラクターのパラメーターとして folderagent を取る別のクラスがありますが、これは Folderagent オブジェクトの防御コピーを作成する正しい方法ですか?
public class FolderKey
{
public FolderAgent folder {get; private set;}
public int returnValue {get; private set;}
public FolderKey(FolderAgent folder, int returnValue)
{
this.folder = new FolderAgent(folder.directoryName, folder.numberofdirectories, folder.numberofFiles, folder.directories, folder.files);
this.returnValue = returnValue;
}
}