473,386 Members | 1,793 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,386 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 1592

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...
1
by: Xing Zhou | last post by:
It seems that XmlSerializer.FromTypes() method cannot handle inner class properly .. or is there anything I did wrong? The following code will throw a reflection exception at FromTypes() method....
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: 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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.