I'm making a filebackup-program using profiles to save settings etc. At the moment the structure is like this:
The MainForm
has a ProfileHandler
that has a bunch of Profile-objects
When you make any changes in the program (adding files to a list, changing destination path etc.) - the settings are saved in a temporary profile. So far, so good...
But when I want to save the profile, I can't really decide which way to go. Right now I pass the temporary profile-object to an AddProfile
method in the ProfileHandler
. The method then creates a new profile object, using the properties from the temporary profile object as parameters (except for a List<string>
, which just copies the content with Addrange).
It works, but is it good?
public bool AddProfile(Profile tempProfile)
{
if (tempProfile != null)
{
Profile profile = new Profile(tempProfile.Name, tempProfile.TargetPath);
profile.Filelist.Clear();
profile.Filelist.AddRange(tempProfile.Filelist);
_profiles.Add(profile);
}
return (tempProfile != null);
}
Is there a slicker way of doing it?
Somehow I feel there must be a simple way to just create a new instance of the Profile
object that is a simple copy of the tempProfile
. In my case the Profile
class only has three fields which makes it easy, but what if it had loads of them?
I hope I'm not too unclear. I'm a bit new at this.