Click here to Skip to main content
11,932,168 members (61,511 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#3.0 C#
This question concerns C# and Design Mode.

Suppose you have a class called Clock with internal properties: Time (DateTime), and Description (string).

Suppose you created a custom class which derives from Control. You add to the custom class a property of type Clock:

private Clock currentTime = DateTime.Now();
public Clock CurrentTime{get{return currentTime;} set{currentTime = value}};

I am confused about getting property serialized.

If I add the attribute

before the property, there doesn't usually seem to be a problem with serialization.

A TypeConverter seems to also have a role in serializing an object. The TypeConverter also seems useful for providing display text in a property grid, for example.

Generally speaking, is the attribute DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] sufficient for serialization, or is a TypeConverter needed in some instances so that Visual Studio knows how to create objects at Design Time?
Posted 21-Nov-12 4:24am
Rohit Shrivastava 21-Nov-12 11:27am
IMO, type converter may be called when you open the designer and you had a default value for the property e.g. CurrentTime="1/1/2011". It will call type converter and allow designer to convert string to date in the example scenario.
BillWoodruff 22-Nov-12 22:48pm
Please tag question with "WinForms," "WPF," or other appropriate tags, your references to "Design Time" here strongly suggest WinForms, but it's always good to be certain, thanks.

I am confused by your code. If you have a non-static class named 'Clock, then this code:

private Clock currentTime = DateTime.Now();

makes no sense, should not even compile: you have not created a new instance of the 'Clock class; and there's no possible overloaded constructor of a class that could possibly use this syntax. And, the following line of code makes no sense either.

Even given the "wild assumption" your 'Clock class was static, this code would make no sense.

Assuming you have working code, please insert a working example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100