473,542 Members | 16,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2777

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

Similar topics

8
3548
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 initially tested my design by building a collection in code and then serializing it to/from an XML file, which worked fine. However, I have hit a...
2
6797
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 XmlSerializer. When this class is decalred as a return value for a WebMethod in an XML WebService I receive the following exception: ...
4
11354
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 should have worked fine since the class in question was already being serialized and deserialized as part of a Web service interface. What I found was...
3
4491
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 XmlText. In my main class, i have created an arraylist which contains a collection of this class FormField. Basically its: public void Add(...
12
8457
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. I, too, am getting nasty FileNotFound exceptions. I've read, and digested the article, and I think I've found a bug -- it's difficult to track,...
3
3152
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 the server (W2K3) it throws an exception. It only seems to happen when serializing/deserializing _arrays_ of a type. If I just serialize/deserialize...
1
1240
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 XmlSerializer, great! Now here is my problem. let say my document conceptually map to classes like that: public class Foo
0
1598
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
5081
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 pluginHandle = Activator.CreateInstanceFrom(assemblyName, type); object plugin = pluginHandle.Unwrap(); ....
0
7321
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7564
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5861
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5237
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1788
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.