Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy object or new object with copied properties?
    text
    copied!<p>I'm making a filebackup-program using profiles to save settings etc. At the moment the structure is like this:</p> <p>The <code>MainForm</code> has a <code>ProfileHandler</code> that has a bunch of Profile-objects</p> <p>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...</p> <p>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 <code>AddProfile</code> method in the <code>ProfileHandler</code>. The method then creates a new profile object, using the properties from the temporary profile object as parameters (except for a <code>List&lt;string&gt;</code>, which just copies the content with Addrange). </p> <p>It works, but is it good?</p> <pre><code>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); } </code></pre> <p>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 <code>Profile</code> object that is a simple copy of the <code>tempProfile</code>. In my case the <code>Profile</code> class only has three fields which makes it easy, but what if it had loads of them?</p> <p>I hope I'm not too unclear. I'm a bit new at this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload