I’ve been doing a lot of work with the .NET XmlSerializer over the last couple of weeks, and once again I’m wishing I had that just one more custom attribute to work with. What I’d love to be able to do is just tell the XmlSerializer to let me worry about a specific part of the XML, since I know better than it.
Something like this (to serialize a property called MyString):
public interface ICustomSerializer
{
void DoSerialization(object theValue, XmlTextWriter w);
void DoDeserialization(XmlNode x, object targetValue)
}
public class DataClass
public DataClass()
[XmlMyWay(typeof(MySerializer))]
public string MyString
get{ return "OK";}
set{}
[AttributeUsage(AttributeTargets.Property)]
public class XmlMyWayAttribute : Attribute
public XmlMyWayAttribute(Type serializer)
public class MySerializer : ICustomSerializer
#region ICustomSerializer Members
public void DoSerialization(object theValue, XmlTextWriter w)
// TODO: Add MySerializer.DoSerialization implementation
public void DoDeserialization(XmlNode x, object targetValue)
// TODO: Add MySerializer.DoDeserialization implementation
#endregion
Then you could do whatever funky serialization you needed to do. Or is this flawed in some fundamental way? It’d be pretty cool though…
Powered by: newtelligence dasBlog 1.9.6264.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2009, Patrick Cauldwell
E-mail