Groups | Blog | Home
all groups > dotnet xml > january 2006 >

dotnet xml : XmlSerializer: Inheritance and Read-Only Properties



Michael Primeaux
1/20/2006 5:29:37 PM
All,

Please maximize for easier viewing. Assume I have a class structure as
follows:

[Serializable]
public class Foo
{
private string _hello = "Hello";

public string Hello
{
get
{
return _hello;
}
}
}

public class Bar : Foo
{
private Foo _fooBar = new Foo();
private string _message = "This is a test";

public Foo FooBar
{
get
{
return _fooBar;
}
}

public string Message
{
get
{
return _message;
}
set
{
_message = value;
}
}
}

When serializing an instance of Bar using the XmlSerializer, I only see the
property named "Message" in my resulting XML string. How can I tell the
XmlSerializer to include all of Bar including read-only properties and all
of Foo (it's base class) in the resulting XML?

Kindest Regards,
Michael



Michael Primeaux
1/21/2006 7:16:05 AM
Please disregard as it seems I'll need to implement the IXmlSerializable
interface. If anyone has other options then please let me know.

- m

[quoted text, click to view]

AddThis Social Bookmark Button