Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

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
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900