473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

La serializzazione che mi fa impazzire

Buongiorno a tutti.

Ho un problema di serializazione. Ne ho già discusso in questo ng, ma non ne sono venuto a capo. Forse non mi ero
spiegato bene. Ora ho capito meglio il problema. Provo a descriverlo con semplicità.

Ho una classe che fa qualcosa con i colori. Tutti i valori di default dei colori naturalmente non vengono serializzati.
Vengono invece serializzati quando sono diversi da quelli di default. Esempio:
Class ColorClass
Private mBackground=Color.White
Public Property Background
'Serializzata se mBackground diverso da Color.White
End Property
End Class

Ho diverse altre classi che hanno varie proprietà che fanno riferimento alla classe dei colori. Queste classi
inizializzano e usano una o più istanze della classe ColorClass per i loro scopi, impostando di volta in volta il colore
che serve e che naturalmente è diverso a secondo di chi lo adopera e del suo uso. Esempio:
Class MyComponent
Private Sfondo as ColorClass
Public Sub New()
Sfondo.Background=Color.Green 'Qui ho modificato il default di ColorClass: verrà serializzato
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Property Sfondo
'Get, Set, ecc.
End Property
End Class

Fin qui tutto bene. Se, a design-time, per esempio cambio il background della classe MyComponent in Color.Red, il nuovo
valore (Color.Red) verrà serializzato perchè Color.Red è diverso sia dal default di ColorClass che dal default di
MyComponent.

Il problema è che se in MyComponent cambio il colore di background in Color.White, questo nuovo valore NON viene
serializzato, e dopo aver rigenerato l'assembly il colore torna a essere Color.Green.
Perchè succede? Succede perchè il nuovo valore che ho impostato a design-time (Color.White) è uguale al default di
ColorClass e quindi non è serializzato e quindi il designer legge il colore di default dell'istanza di MyComponent, cioè
Color.Green. E questo è un problema, perchè io volevo che il background fosse bianco, e non verde.

E' un problema di logica e confesso che con mi è stato facile comprenderne il meccanismo, soprattutto in una gerarchia
di classi un po' complessa. Quando il tipo è booleano, o è un qualsiasi Enum, la probabilità che il problema si
verifichi sono elevate.

Una soluzione sarebbe forzare la serializzazione (ShouldSerializexxx=True oppure eliminando i defaults) ma questa non la
considero una soluzione: è una brutalità.

Bene, se c'è un modo per evitare che questo succeda, io non l'ho trovato. Magari è una sciocchezza...

Qualcuno ha un'idea?

Grazie

Carlo


-------------------------------------------
Carlo, MCP (Windows Based Applications)
ca************@gmail.com
Milan, Italy



Nov 21 '05 #1
0 1131

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gilberto Carcano | last post by:
Is there a way to avoid public custom properties to persist in the ASPX code? I'have a class for columns collection in a Web Control i'm writing. This class must to implement the IStateManager...
1
by: Marco Tibolla | last post by:
Buongiorno a tutti, ho un problema che mi fa impazzire :-( Ho creato un WebService per sincronizzare una cartella nel mio PC locale con il mio sito internet. La cartella contiene dei file PDF....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.