-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed expression<func> from readxml, no need or it in generated code.
- Loading branch information
1 parent
c1a9835
commit c62b774
Showing
31 changed files
with
105 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace Gu.Units.Tests | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Xml.Serialization; | ||
using NUnit.Framework; | ||
|
||
public class SerializationTests | ||
{ | ||
[Test] | ||
public void RoundtripXml() | ||
{ | ||
var length = new Length(1.2, LengthUnit.Metres); | ||
var roundtrip = Roundtrip(length); | ||
Assert.AreEqual(length, roundtrip); | ||
var dummy = new Dummy(length); | ||
var roundtripDummy = Roundtrip(dummy); | ||
Assert.AreEqual(length, roundtripDummy.Length); | ||
} | ||
|
||
private T Roundtrip<T>(T value) | ||
{ | ||
var serializer = new XmlSerializer(typeof(T)); | ||
var builder = new StringBuilder(); | ||
string xml; | ||
using (var writer = new StringWriter(builder)) | ||
{ | ||
serializer.Serialize(writer, value); | ||
xml = builder.ToString(); | ||
//Assert.AreEqual(@"<Length Value=""1.2"" />",); | ||
} | ||
using (var reader = new StringReader(xml)) | ||
{ | ||
var deserialize = (T)serializer.Deserialize(reader); | ||
return deserialize; | ||
} | ||
} | ||
|
||
public class Dummy | ||
{ | ||
private Dummy() | ||
{ | ||
} | ||
|
||
public Dummy(Length length) | ||
{ | ||
Length = length; | ||
} | ||
|
||
public Length Length { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
namespace Gu.Units | ||
{ | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Xml; | ||
using System.Xml.Linq; | ||
|
||
public class XmlExt | ||
{ | ||
public static void SetReadonlyField<T>(ref T force, Func<T, object> func, double toDouble) | ||
internal static void SetReadonlyField<T>(ref T self, string fieldName, XmlReader reader, string attributeName) | ||
where T : IQuantity | ||
{ | ||
throw new NotImplementedException(); | ||
reader.MoveToContent(); | ||
var d = XmlConvert.ToDouble(reader.GetAttribute(attributeName)); | ||
reader.ReadStartElement(); | ||
SetReadonlyField(ref self, fieldName, d); | ||
} | ||
|
||
public static string ReadAttributeOrElementOrDefault(XElement xElement, string value) | ||
private static void SetReadonlyField<T>(ref T self, string fieldName, double value) | ||
where T : IQuantity | ||
{ | ||
throw new NotImplementedException(); | ||
var fieldInfo = self.GetType() | ||
.GetField(fieldName); | ||
object boxed = self; | ||
fieldInfo.SetValue(boxed, value); | ||
self = (T)boxed; | ||
} | ||
|
||
public static void WriteAttribute(XmlWriter writer, string value, double newtons) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
public static void SetReadonlyField<T>(ref T force, Func<T, double> func, XmlReader reader, string value) | ||
where T : IQuantity | ||
|
||
internal static void WriteAttribute(XmlWriter writer, string name, double value) | ||
{ | ||
reader.MoveToContent(); | ||
writer.WriteStartAttribute(name); | ||
writer.WriteValue(value); | ||
writer.WriteEndAttribute(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters