From: Owen R. <exo...@us...> - 2005-09-08 01:07:56
|
Update of /cvsroot/netreflector/NetReflector/src/NetReflector/Serialisers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10450/src/NetReflector/Serialisers Modified Files: XmlArraySerialiser.cs XmlCollectionSerialiser.cs XmlDictionarySerialiser.cs XmlMemberSerialiser.cs XmlTypeSerialiser.cs Added Files: DefaultSerialiserFactory.cs ISerialiserFactory.cs Log Message: NETREF-5: adding support for customisable serialisation. attributes use DefaultSerialiserFactory by default -- however clients can override for more control over serialisation process. Index: XmlDictionarySerialiser.cs =================================================================== RCS file: /cvsroot/netreflector/NetReflector/src/NetReflector/Serialisers/XmlDictionarySerialiser.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XmlDictionarySerialiser.cs 7 Apr 2005 04:30:40 -0000 1.4 --- XmlDictionarySerialiser.cs 8 Sep 2005 01:07:47 -0000 1.5 *************** *** 1,7 **** - using Exortech.NetReflector.Util; using System; using System.Collections; - using System.Reflection; using System.Xml; namespace Exortech.NetReflector --- 1,6 ---- using System; using System.Collections; using System.Xml; + using Exortech.NetReflector.Util; namespace Exortech.NetReflector *************** *** 12,17 **** private string elementName = "string"; ! public XmlDictionarySerialiser(MemberInfo member, ReflectorHashAttribute attribute) : base(member, attribute) ! { this.attribute = attribute; } --- 11,16 ---- private string elementName = "string"; ! public XmlDictionarySerialiser(ReflectorMember member, ReflectorHashAttribute attribute) : base(member, attribute) ! { this.attribute = attribute; } *************** *** 19,23 **** protected override void WriteValue(XmlWriter writer, object value) { ! IDictionary dictionary = (IDictionary)value; foreach (object key in dictionary.Keys) { --- 18,22 ---- protected override void WriteValue(XmlWriter writer, object value) { ! IDictionary dictionary = (IDictionary) value; foreach (object key in dictionary.Keys) { *************** *** 38,44 **** writer.WriteAttributeString(attribute.Key, key.ToString()); ! XmlTypeSerialiser serialiser = (XmlTypeSerialiser)typeAttribute.CreateSerialiser(target.GetType()); serialiser.WriteMembers(writer, target); ! writer.WriteEndElement(); } --- 37,43 ---- writer.WriteAttributeString(attribute.Key, key.ToString()); ! XmlTypeSerialiser serialiser = (XmlTypeSerialiser) typeAttribute.CreateSerialiser(target.GetType()); serialiser.WriteMembers(writer, target); ! writer.WriteEndElement(); } *************** *** 64,66 **** } } ! } --- 63,65 ---- } } ! } \ No newline at end of file --- NEW FILE: DefaultSerialiserFactory.cs --- using System.Collections; using Exortech.NetReflector.Util; namespace Exortech.NetReflector { public class DefaultSerialiserFactory : ISerialiserFactory { public IXmlSerialiser Create(ReflectorMember member, ReflectorPropertyAttribute attribute) { if (member.MemberType.IsArray) { return new XmlArraySerialiser(member, attribute); } else if (typeof(ICollection).IsAssignableFrom(member.MemberType)) { return new XmlCollectionSerialiser(member, attribute); } return new XmlMemberSerialiser(member, attribute); } } } Index: XmlArraySerialiser.cs =================================================================== RCS file: /cvsroot/netreflector/NetReflector/src/NetReflector/Serialisers/XmlArraySerialiser.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XmlArraySerialiser.cs 7 Apr 2005 04:30:40 -0000 1.4 --- XmlArraySerialiser.cs 8 Sep 2005 01:07:47 -0000 1.5 *************** *** 1,4 **** using System; - using System.Reflection; using System.Xml; using Exortech.NetReflector.Util; --- 1,3 ---- *************** *** 10,14 **** protected readonly ReflectorTypeConverter converter; ! public XmlArraySerialiser(MemberInfo member, ReflectorPropertyAttribute attribute) : base(member, attribute) { converter = new ReflectorTypeConverter(); --- 9,13 ---- protected readonly ReflectorTypeConverter converter; ! public XmlArraySerialiser(ReflectorMember member, ReflectorPropertyAttribute attribute) : base(member, attribute) { converter = new ReflectorTypeConverter(); --- NEW FILE: ISerialiserFactory.cs --- using System.Reflection; using Exortech.NetReflector.Util; namespace Exortech.NetReflector { public interface ISerialiserFactory { IXmlSerialiser Create(ReflectorMember memberInfo, ReflectorPropertyAttribute attribute); } } Index: XmlMemberSerialiser.cs =================================================================== RCS file: /cvsroot/netreflector/NetReflector/src/NetReflector/Serialisers/XmlMemberSerialiser.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** XmlMemberSerialiser.cs 25 Jun 2005 01:40:16 -0000 1.10 --- XmlMemberSerialiser.cs 8 Sep 2005 01:07:47 -0000 1.11 *************** *** 1,4 **** using System; - using System.Reflection; using System.Xml; using Exortech.NetReflector.Util; --- 1,3 ---- *************** *** 12,18 **** private IInstantiator instantiator; ! public XmlMemberSerialiser(MemberInfo member, ReflectorPropertyAttribute attribute) { ! this.member = Util.ReflectorMember.Create(member); this.attribute = attribute; this.instantiator = new DefaultInstantiator(); --- 11,17 ---- private IInstantiator instantiator; ! public XmlMemberSerialiser(ReflectorMember member, ReflectorPropertyAttribute attribute) { ! this.member = member; this.attribute = attribute; this.instantiator = new DefaultInstantiator(); Index: XmlCollectionSerialiser.cs =================================================================== RCS file: /cvsroot/netreflector/NetReflector/src/NetReflector/Serialisers/XmlCollectionSerialiser.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** XmlCollectionSerialiser.cs 7 Apr 2005 04:30:40 -0000 1.4 --- XmlCollectionSerialiser.cs 8 Sep 2005 01:07:47 -0000 1.5 *************** *** 1,7 **** - using Exortech.NetReflector.Util; using System; using System.Collections; - using System.Reflection; using System.Xml; namespace Exortech.NetReflector --- 1,6 ---- using System; using System.Collections; using System.Xml; + using Exortech.NetReflector.Util; namespace Exortech.NetReflector *************** *** 11,19 **** private static readonly string elementName = "string"; ! public XmlCollectionSerialiser(MemberInfo member, ReflectorPropertyAttribute attribute) : base(member, attribute) { } protected override void WriteValue(XmlWriter writer, object value) { ! foreach (object element in ((IEnumerable)value)) { if (element == null) continue; --- 10,19 ---- private static readonly string elementName = "string"; ! public XmlCollectionSerialiser(ReflectorMember member, ReflectorPropertyAttribute attribute) : base(member, attribute) ! {} protected override void WriteValue(XmlWriter writer, object value) { ! foreach (object element in ((IEnumerable) value)) { if (element == null) continue; *************** *** 45,47 **** } } ! } --- 45,47 ---- } } ! } \ No newline at end of file Index: XmlTypeSerialiser.cs =================================================================== RCS file: /cvsroot/netreflector/NetReflector/src/NetReflector/Serialisers/XmlTypeSerialiser.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** XmlTypeSerialiser.cs 25 Jun 2005 01:40:17 -0000 1.9 --- XmlTypeSerialiser.cs 8 Sep 2005 01:07:47 -0000 1.10 *************** *** 59,63 **** if (attribute != null) { ! serialisers.Add(attribute.CreateSerialiser(member)); } } --- 59,63 ---- if (attribute != null) { ! serialisers.Add(attribute.CreateSerialiser(ReflectorMember.Create(member))); } } |