Skip to content

Commit

Permalink
Added ability to serialize messages containing Uri-s to xml.
Browse files Browse the repository at this point in the history
  • Loading branch information
udidahan committed Dec 21, 2010
1 parent 41a6f62 commit c82ddf2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/impl/Serializers/NServiceBus.Serializers.XML.Test/IM1.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
namespace NServiceBus.Serializers.XML
using System;

namespace NServiceBus.Serializers.XML
{
public interface IM1 : IMessage
{
float Age { get; set; }
int Int { get; set; }
string Name { get; set; }
string Address { get; set; }
Uri Uri { get; set; }
Risk Risk { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class M1 : IM1
public int Int { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public Uri Uri { get; set; }
public Risk Risk { get; set; }
public string this[int key]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void TestInterfaces()
o.Address = Guid.NewGuid().ToString();
o.Int = 7;
o.Name = "udi";
o.Uri = new Uri("http://www.UdiDahan.com/");
o.Risk = new Risk { Percent = 0.15D, Annum = true, Accuracy = 0.314M };
o.Some = SomeEnum.B;
o.Start = DateTime.Now;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private object Process(XmlNode node, object parent)

private object GetObjectOfTypeFromNode(Type t, XmlNode node)
{
if (t.IsSimpleType())
if (t.IsSimpleType() || t == typeof(Uri))
return GetPropertyValue(t, node);

if (t == typeof(WireEncryptedString))
Expand Down Expand Up @@ -477,6 +477,9 @@ private object GetPropertyValue(Type type, XmlNode n)

if (type == typeof(byte[]))
return Convert.FromBase64String(n.ChildNodes[0].InnerText);

if (type == typeof(Uri))
return new Uri(n.ChildNodes[0].InnerText);
}

//Handle dictionaries
Expand Down Expand Up @@ -656,6 +659,12 @@ private void WriteObject(string name, Type type, object value, StringBuilder bui
return;
}

if (value is Uri)
{
builder.AppendFormat("<{0}>{1}</{0}>\n", name, value);
return;
}

string element = name;
string prefix;
namespacesToPrefix.TryGetValue(type.Namespace, out prefix);
Expand Down

0 comments on commit c82ddf2

Please sign in to comment.