473,394 Members | 1,749 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,394 software developers and data experts.

XMLSerializer problem, class inside class

Hi,

I'm having a problem with XMLSerializer, I have classes like the
following:

[Serializable]
public abstract class EulerObject
{
private Rectangle rect;
private string guid = "";

public virtual Rectangle Rect
{
get { return rect; }
set{ rect = value; }
}

public string GUID
{
get { return guid; }
set { guid = value; }
}

public abstract void Draw(Graphics g);

public abstract EulerObject MakeCopy(bool sameGuid);
}

[Serializable]
public abstract class EulerShape : EulerObject
{
private GraphicsPath graphPath;
private EulerLabel label = null;

public override Rectangle Rect
{
// do stuff
}

public abstract EulerShapes.ShapeType ShapeType
{
get;// { return shapeType; }
}

[XmlIgnore]
[SoapIgnore]
public GraphicsPath GraphPath
{
// stuff
}

public EulerLabel Label
{
get { return label; }
set { label = value; }
}

public EulerShape() { }
public abstract GraphicsPath CreateGraphicsPath(Rectangle
rect);
}

[Serializable]
public class EulerShapeElipse : EulerShape
{
public override EulerShapes.ShapeType ShapeType
{
get { return EulerShapes.ShapeType.Elipse; }
}

public EulerShapeElipse() : base() { }

public EulerShapeElipse(Rectangle theRect) : base(theRect) { }

public EulerShapeElipse(String uid, Rectangle theRect) :
base(uid, theRect) { }

public override GraphicsPath CreateGraphicsPath(Rectangle
rect)
{
GraphicsPath tempPath = new GraphicsPath();

tempPath.AddArc(rect, 0, 360);

return tempPath;
}

public override void Draw(Graphics g)
{
g.DrawPath(Pens.Black, this.GraphPath);

if (Label != null)
Label.Draw(g);
}

public override EulerObject MakeCopy(bool keepGuid)
{
EulerShapeElipse tempShape = new
EulerShapeElipse(this.Rect);

if (keepGuid == true)
tempShape.GUID = this.GUID;

return tempShape;
}
}

[Serializable]
public class EulerLabel : EulerObject
{
private string label;
private Font fontUsed;

public XmlFont Font
{
get { return new XmlFont(fontUsed); }
set { fontUsed = value.ToFont(); }
}

[XmlIgnore]
public Font FontUsed
{
get { return fontUsed; }
set { fontUsed = value; }
}

public string Label
{
get { return label; }
set { label = value; }
}

public EulerLabel()
{
this.fontUsed = SystemFonts.DefaultFont;
}

public override void Draw(Graphics g)
{
System.Windows.Forms.TextRenderer.DrawText(g, label,
fontUsed, this.Rect, Color.Black);
}

public override EulerObject MakeCopy(bool keepGuid)
{
EulerLabel tempLabel = new EulerLabel(this.Rect,
this.Label, this.FontUsed);

if (keepGuid == true)
tempLabel.GUID = this.GUID;

return tempLabel;
}
}

//http://www.codeproject.com/soap/xmlsettings.asp
[Serializable]
public struct XmlFont
{
public string FontFamily;
public GraphicsUnit GraphicsUnit;
public float Size;
public FontStyle Style;

public XmlFont(Font f)
{
FontFamily = f.FontFamily.Name;
GraphicsUnit = f.Unit;
Size = f.Size;
Style = f.Style;
}

public Font ToFont()
{
return new Font(FontFamily, Size, Style,
GraphicsUnit);
}
}

I have a few more classes that inherit from EulerShape.

I have a List<EulerShapethat contains various shapes that inherit
from EulerShape.

When using XMLSerializer it wont serialize the Label property inside
the classes based on EulerShape, yet it will serialize the EulerLabel
class itself if its not inside another class.

I've tried telling it to serialize the property by putting
[XmlAttribute(typeof(EulerLabel))] above it, but this then causes the
program to crash when trying to serialize it.

If anyone has a solution I'd apprechiate it, I have to try and solve
this problem ASAP so I can continue with a study for my dissertation
involving this application.

Regards,
Kris Wragg
BSc Software Engineering, 4th Year
Sheffield Hallam University

Mar 5 '07 #1
0 2769

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

Similar topics

8
by: Harris Boyce | last post by:
Hello, I'm trying to use the FOR XML EXPLICIT clause with SQL Server to deserialize data from my database into a strongly-typed collection object that I will use throughout my application. I...
2
by: Chris Aitchison | last post by:
Hello, I am attempting to have a class that I have written serialize so that it can be both passed as a parameter or return value for a webservice, and also be serialized to disk using the...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
3
by: Loui Mercieca | last post by:
Hi, I have created a class, named FormField , which basically contains two fields, name and value. I have set the tag before the class and the field is set as an XmlAttribute whil the name as...
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
3
by: Don McNamara | last post by:
Hi, I've hit quite a strange problem with XmlSerializer on my W2K3 server. When I serialize/deserialize using an exe on my local computer (XP), everything works fine. When I put the code out on...
1
by: Lloyd Dupont | last post by:
I get an XmlDocument from an external source. I want to load it/map it to C# class. I'm creating classes as I learn about the format. many tag are yet unparsed, but that seems ok for the...
0
by: Kristopher Wragg | last post by:
Hi, I'm having a problem with XMLSerializer, I have classes like the following: public abstract class EulerObject { private Rectangle rect; private string guid = "";
2
by: christopher.watford | last post by:
I'm loading a plugin assembly using Activator.CreateInstanceFrom, and inside this assembly is a settings class which gets serialized to XML. The general code flow is as follows: ObjectHandle...
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: 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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.