Click here to Skip to main content
15,918,267 members
Home / Discussions / C#
   

C#

 
AnswerRe: Copying objects by value Pin
originSH16-Jul-07 22:09
originSH16-Jul-07 22:09 
AnswerRe: Copying objects by value Pin
Luc Pattyn16-Jul-07 22:47
sitebuilderLuc Pattyn16-Jul-07 22:47 
GeneralRe: Copying objects by value Pin
jozsurf16-Jul-07 23:42
jozsurf16-Jul-07 23:42 
GeneralRe: Copying objects by value Pin
Luc Pattyn17-Jul-07 0:20
sitebuilderLuc Pattyn17-Jul-07 0:20 
GeneralRe: Copying objects by value Pin
jozsurf17-Jul-07 15:06
jozsurf17-Jul-07 15:06 
GeneralRe: Copying objects by value Pin
Luc Pattyn17-Jul-07 16:45
sitebuilderLuc Pattyn17-Jul-07 16:45 
GeneralRe: Copying objects by value Pin
jozsurf17-Jul-07 16:59
jozsurf17-Jul-07 16:59 
GeneralRe: Copying objects by value [modified] Pin
Luc Pattyn17-Jul-07 17:15
sitebuilderLuc Pattyn17-Jul-07 17:15 
Hi,

as the default settings are hardcoded and not obtained by parsing an XML file
(hence cheap to reproduce), seems to me the following scheme would do just fine:

1. have class "Settings" with a single constructor, returning a Settings object with
everything set to its default value.

2. do settings=new Settings(); when you need the default settings;

3. do settings=new Settings(); followed by whatever you like, when you want modified
settings

4. do again settings=new Settings(); when you need to revert to the default settings.

In doing so, you dont see any Copy() or Clone() operation; you simply start from the
default, and modify what needs being modified.


One slight modification could be to provide a Clear() method, which sets all
settings in a Settings instance to their default values (obviously now the
constructor would simply call Clear() itself). This allows you to reuse a Settings
object, if you consider this relevant.

[Edit: I guess Reset() is a better name]


One other idea would be to turn Settings into a struct (assuming you stick with
values and structs, again containing only values and structs, etc ad infinitum).
Now settings1=settings2 would really copy everything.
Nevertheless, I do prefer the former approach, because I like "new Settings()";
it shows you get a new object with settings, and it does not limit the members to value types.
(in my apps a lot of settings tend to be strings).

Hope this helps

Smile | :)




-- modified at 23:42 Tuesday 17th July, 2007


GeneralRe: Copying objects by value Pin
jozsurf17-Jul-07 18:07
jozsurf17-Jul-07 18:07 
GeneralRe: Copying objects by value Pin
Luc Pattyn22-Jul-07 12:00
sitebuilderLuc Pattyn22-Jul-07 12:00 
QuestionHow to set and get Windows Application's Version? Pin
Khoramdin16-Jul-07 17:21
Khoramdin16-Jul-07 17:21 
AnswerRe: How to set and get Windows Application's Version? Pin
Vikram A Punathambekar16-Jul-07 17:40
Vikram A Punathambekar16-Jul-07 17:40 
QuestionRe: How to set and get Windows Application's Version? Pin
Khoramdin16-Jul-07 19:20
Khoramdin16-Jul-07 19:20 
AnswerRe: How to set and get Windows Application's Version? Pin
Vikram A Punathambekar16-Jul-07 21:05
Vikram A Punathambekar16-Jul-07 21:05 
AnswerRe: How to set and get Windows Application's Version? Pin
originSH16-Jul-07 22:14
originSH16-Jul-07 22:14 
AnswerRe: How to set and get Windows Application's Version? Pin
ekynox17-Jul-07 13:33
ekynox17-Jul-07 13:33 
QuestionDataGrid date AND time Column[modified] Pin
swjam16-Jul-07 14:24
swjam16-Jul-07 14:24 
AnswerRe: DataGrid date AND time Column[modified] Pin
Michael Sync16-Jul-07 17:39
Michael Sync16-Jul-07 17:39 
GeneralRe: DataGrid date AND time Column[modified] Pin
swjam16-Jul-07 20:59
swjam16-Jul-07 20:59 
GeneralRe: DataGrid date AND time Column[modified] Pin
Rhys Gravell16-Jul-07 23:09
professionalRhys Gravell16-Jul-07 23:09 
Questionadd a page Pin
daku116-Jul-07 12:47
daku116-Jul-07 12:47 
AnswerRe: add a page Pin
T.EDY16-Jul-07 17:06
T.EDY16-Jul-07 17:06 
AnswerRe: add a page Pin
Sathesh Sakthivel16-Jul-07 17:20
Sathesh Sakthivel16-Jul-07 17:20 
Questionthrow exception does not work in timer event??? Pin
Togg16-Jul-07 12:38
Togg16-Jul-07 12:38 
AnswerRe: throw exception does not work in timer event??? Pin
Luc Pattyn16-Jul-07 14:23
sitebuilderLuc Pattyn16-Jul-07 14:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.