views:

237

answers:

1
A: 

I can't really read VB.NET code, since it makes my eyes bleed, but if I understand your code correctly, you're doing the font initialization as a member initializer. This is run during construction time, but the XML deserialization happens, basically, afterwards: The object is created (that's why it needs a parameterless constructor), and then the properties that are found in the XML are being set. So, basically, you're reading the properties too early.

My solution to this was to have an actual Font property with a getter that creates the font from these properties. This way, the actual font object is created when you need it (when you get the property), and that is typically after deserialization. It's still up to you whether you just return a new font object every time in the getter, or cache it for subsequent calls. I prefer the former, and then immediately dispose of the font object after use.

Note: The syntax for code on StackOverflow is not BBCode, but just indenting everything with four spaces. Select the code, and then press the button with the zeros and ones on it. I fixed it for this post.

OregonGhost
Thnx I was just editing and now I'm reading your post. Looks very helpfull! I'll look into it .... Thank you for the reply much appreciated.
jovany
OOoh I think I understand what you mean, but I already tried that. You can see the commented code <XmlAttributeAttribute("FontFamily")> _ Public Property FontFamilyGet() As String Get Return FontFamily End Get Set(ByVal value As String) FontFamily = value End Set End Property <XmlAttributeAttribute("FontType")> _ Public Property FontType_() As Integer Get Return FontType End Get Set(ByVal value As Integer) FontType = value End Set End PropertyUnfortunately no
jovany
I don't understand what you mean. Just create a getter like this: `public Font Font { get { return new Font(FontFamily, ...); } };` (sorry, no VB.NET, I'm in C#) and you won't get problems. You can edit your question to go into more detail of what you already tried, the comments are rather limited for this.
OregonGhost
mmmm ok let me put some stuff in update.And this is what I also tried.
jovany