Click here to Skip to main content
15,887,135 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: how to configure an applicaiton in .net Pin
Stephane Rodriguez.10-Mar-03 21:58
Stephane Rodriguez.10-Mar-03 21:58 
GeneralError while putting usercontrol on tabcontrol Pin
nguyentuancuong5-Mar-03 14:06
nguyentuancuong5-Mar-03 14:06 
GeneralDebug or Release Pin
Pierre-Yves Troel4-Mar-03 7:37
Pierre-Yves Troel4-Mar-03 7:37 
GeneralRe: Debug or Release Pin
Stephane Rodriguez.4-Mar-03 11:29
Stephane Rodriguez.4-Mar-03 11:29 
GeneralRe: Debug or Release Pin
Pierre Yves Troel4-Mar-03 17:05
sussPierre Yves Troel4-Mar-03 17:05 
GeneralRe: Debug or Release Pin
Stephane Rodriguez.5-Mar-03 5:29
Stephane Rodriguez.5-Mar-03 5:29 
GeneralLicensed Controls on Web Pages Pin
NigelSavidge4-Mar-03 4:53
NigelSavidge4-Mar-03 4:53 
GeneralPlease Heeelp - ShouldSerializeMyProperty problem Pin
Uriel Cohen4-Mar-03 3:01
Uriel Cohen4-Mar-03 3:01 
I have a little problem working with the ShouldSerializeMyProperty methods to tell the code serializer of the designer when to serialize my property. I need some complex conditions so I cannot use the DefaultValueAttribute.

I tried the following code:

public class MyForm : Form 
{ 
    public MyForm() 
    { 
        this.extraColor = Color.Red; 
        this.extraValue = 0; 
        this.layerData = new LayerData(); 
    } 

    public Color ExtraColor 
    { 
        get { return this.extraColor; } 
        set { this.extraColor = value; } 
    } 
    bool ShouldSerializeExtraColor() 
    { 
        Color color; 
        if (this.extraValue == 0) color = Color.Red; 
        else color = Color.Blue; 
        return !(this.extraColor == color); 
    } 

    public int ExtraValue 
    { 
        get { return this.extraValue; } 
        set { this.extraValue = value; } 
    } 
    bool ShouldSerializeExtraValue() 
    { 
        return !(this.extraValue == 0); 
    } 

    private int extraValue; 
    private Color extraColor; 
} 

Then I inherited MyForm in the following way:
public class Form1 : MyForm { ... } 

When I opened Form1 in the designer and changed ExtraValue to 1 (from 0) then it gets serialized, but ExtraColor doesn't (it should serialize with a value of Color.Red). Then I changed ExtraColor to Blue and it gets serialized (though it shouldn't). It looks like the ShouldSerializeMyProperty is not executed dynamically, but hardcoded or something.
The most interesting of all is that I tried doing the same thing with a Panel (inheriting Panel to create MyPanel, and then MyPanel to create Panel1) and it worked as it should when I place a Panel1 on a Form and change the properties as explained before.

I also tried to attach another Visual Studio as a debugger to the serialization process. I put a breakpoint inside the ShouldSerializeExtraColor method, and when I tried it with the Panel version it gets called and returned the correct boolean value. When I tried it with the Form (as in the previous code) I found out that the ShouldSerializeExtraColor doesn't even get called Confused | :confused:

I really would appreciate help with this problem..

Sorry for the long post.

Uriel
GeneralRe: Please Heeelp - ShouldSerializeMyProperty problem Pin
Bo Hunter16-Mar-03 17:05
Bo Hunter16-Mar-03 17:05 
GeneralRe: Please Heeelp - ShouldSerializeMyProperty problem Pin
Uriel16-Mar-03 18:14
Uriel16-Mar-03 18:14 
QuestionWhich .NET developer magazine? Pin
Oyvind Bratland4-Mar-03 2:24
Oyvind Bratland4-Mar-03 2:24 
GeneralWhere to get the COM+ Current Object Count Pin
Gaul3-Mar-03 9:23
Gaul3-Mar-03 9:23 
GeneralHelp: Unable To Copy Data (In Structure) from Unmanged MFC/C++ App to .NET Pin
Gaul3-Mar-03 9:05
Gaul3-Mar-03 9:05 
QuestionSystem.Drawing.Drawing3D? Pin
Ioncycle3-Mar-03 5:30
Ioncycle3-Mar-03 5:30 
AnswerRe: System.Drawing.Drawing3D? Pin
leppie3-Mar-03 8:59
leppie3-Mar-03 8:59 
GeneralRe: System.Drawing.Drawing3D? Pin
Ioncycle21-Mar-03 11:56
Ioncycle21-Mar-03 11:56 
GeneralInterop - Marshaling nested structs Pin
Nathan Tran2-Mar-03 19:03
Nathan Tran2-Mar-03 19:03 
GeneralRemoting over internet (events) Pin
Richard P S2-Mar-03 9:24
Richard P S2-Mar-03 9:24 
GeneralRe: Remoting over internet (events) Pin
John Davis2-Mar-03 10:48
John Davis2-Mar-03 10:48 
GeneralRe: Remoting over internet (events) Pin
Richard P S3-Mar-03 0:29
Richard P S3-Mar-03 0:29 
GeneralRe: Remoting over internet (events) Pin
John Davis3-Mar-03 4:33
John Davis3-Mar-03 4:33 
Generalwfc in J# Pin
ashwathi1-Mar-03 18:26
ashwathi1-Mar-03 18:26 
General.NET Serialization Pin
LindaK28-Feb-03 9:54
LindaK28-Feb-03 9:54 
QuestionHow to remove assembly at runtime Pin
nguyentuancuong27-Feb-03 15:06
nguyentuancuong27-Feb-03 15:06 
AnswerRe: How to remove assembly at runtime Pin
leppie28-Feb-03 6:13
leppie28-Feb-03 6:13 

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.