Skip to content

Commit

Permalink
Fix missing System.Xml reference.
Browse files Browse the repository at this point in the history
Make CodeWScope not longer depend on Code.
Add fix some more failing XmlSerializer tests.
  • Loading branch information
lanwin committed May 22, 2010
1 parent 7180367 commit d0784c3
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 63 deletions.
1 change: 1 addition & 0 deletions examples/Simple/Simple.csproj
Expand Up @@ -52,6 +52,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Configuration" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
Expand Down
7 changes: 4 additions & 3 deletions examples/SimpleVB/SimpleVB.vbproj
Expand Up @@ -56,6 +56,7 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Application.vb" />
Expand All @@ -70,9 +71,6 @@
<Name>MongoDB</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
Expand All @@ -90,5 +88,8 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
</Project>
1 change: 1 addition & 0 deletions source/MongoDB.GridFS.Tests/MongoDB.GridFS.Tests.csproj
Expand Up @@ -59,6 +59,7 @@
<HintPath>..\..\redist\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GridFileInfoTest.cs" />
Expand Down
1 change: 1 addition & 0 deletions source/MongoDB.GridFS/MongoDB.GridFS.csproj
Expand Up @@ -62,6 +62,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\AssemblyInfoGlobal.cs">
Expand Down
27 changes: 27 additions & 0 deletions source/MongoDB.Tests/UnitTests/TestCodeWScope.cs
@@ -1,5 +1,6 @@
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
using NUnit.Framework;

namespace MongoDB.UnitTests
Expand Down Expand Up @@ -46,5 +47,31 @@ public void CanBeEqual()

Assert.AreEqual(code1, code2);
}

[Test]
public void CanBeXmlSerialized()
{
var source = new CodeWScope("code",new Document("key","value"));
var serializer = new XmlSerializer(typeof(CodeWScope));

var writer = new StringWriter();
serializer.Serialize(writer, source);
var dest = (CodeWScope)serializer.Deserialize(new StringReader(writer.ToString()));

Assert.AreEqual(source, dest);
}

[Test]
public void CanBeXmlSerializedWithNullValue()
{
var source = new CodeWScope(null,null);
var serializer = new XmlSerializer(typeof(CodeWScope));

var writer = new StringWriter();
serializer.Serialize(writer, source);
var dest = (CodeWScope)serializer.Deserialize(new StringReader(writer.ToString()));

Assert.AreEqual(source, dest);
}
}
}
2 changes: 1 addition & 1 deletion source/MongoDB.Tests/UnitTests/TestDBRef.cs
Expand Up @@ -28,7 +28,7 @@ public void CanBeBinarySerialized()
public void CanBeXmlSerialized()
{
var source = new DBRef("collection", "id");
var serializer = new XmlSerializer(typeof(Oid));
var serializer = new XmlSerializer(typeof(DBRef));

var writer = new StringWriter();
serializer.Serialize(writer, source);
Expand Down
38 changes: 1 addition & 37 deletions source/MongoDB/Code.cs
@@ -1,15 +1,12 @@
using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using MongoDB.Util;

namespace MongoDB
{
/// <summary>
/// </summary>
[Serializable]
public class Code : IEquatable<Code>, IXmlSerializable
public class Code : IEquatable<Code>
{
/// <summary>
/// Initializes a new instance of the <see cref = "Code" /> class.
Expand Down Expand Up @@ -109,38 +106,5 @@ public override string ToString()
{
return string.Format(@"{{ ""$code"": ""{0}"" }}", JsonFormatter.Escape(Value));
}

/// <summary>
/// This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"/> to the class.
/// </summary>
/// <returns>
/// An <see cref="T:System.Xml.Schema.XmlSchema"/> that describes the XML representation of the object that is produced by the <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)"/> method and consumed by the <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)"/> method.
/// </returns>
XmlSchema IXmlSerializable.GetSchema()
{
return null;
}

/// <summary>
/// Generates an object from its XML representation.
/// </summary>
/// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
void IXmlSerializable.ReadXml(XmlReader reader)
{
if(reader.IsEmptyElement)
return;

Value = reader.ReadString();
}

/// <summary>
/// Converts an object into its XML representation.
/// </summary>
/// <param name="writer">The <see cref="T:System.Xml.XmlWriter"/> stream to which the object is serialized.</param>
void IXmlSerializable.WriteXml(XmlWriter writer)
{
if(Value != null)
writer.WriteString(Value);
}
}
}
49 changes: 28 additions & 21 deletions source/MongoDB/CodeWScope.cs
@@ -1,12 +1,11 @@
using System;
using System.Xml.Serialization;

namespace MongoDB
{
/// <summary>
/// </summary>
[Serializable]
public class CodeWScope : Code, IEquatable<CodeWScope>
public class CodeWScope : IEquatable<CodeWScope>
{
/// <summary>
/// Initializes a new instance of the <see cref = "CodeWScope" /> class.
Expand Down Expand Up @@ -35,75 +34,83 @@ public CodeWScope(String code, Document scope)
Scope = scope;
}

/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>The value.</value>
public string Value { get; set; }

/// <summary>
/// Gets or sets the scope.
/// </summary>
/// <value>The scope.</value>
public Document Scope { get; set; }

/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <param name = "other">An object to compare with this object.</param>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// true if the current object is equal to the <paramref name = "other" /> parameter; otherwise, false.
/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
/// </returns>
public bool Equals(CodeWScope other)
{
if(ReferenceEquals(null, other))
return false;
if(ReferenceEquals(this, other))
return true;
return base.Equals(other) && Equals(other.Scope, Scope);
return Equals(other.Value, Value) && Equals(other.Scope, Scope);
}

/// <summary>
/// Determines whether the specified <see cref = "System.Object" /> is equal to this instance.
/// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
/// </summary>
/// <param name = "obj">The <see cref = "System.Object" /> to compare with this instance.</param>
/// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref = "System.Object" /> is equal to this instance; otherwise, <c>false</c>.
/// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
/// <exception cref = "T:System.NullReferenceException">
/// The <paramref name = "obj" /> parameter is null.
/// <exception cref="T:System.NullReferenceException">
/// The <paramref name="obj"/> parameter is null.
/// </exception>
public override bool Equals(object obj)
{
if(ReferenceEquals(null, obj))
return false;
return ReferenceEquals(this, obj) || Equals(obj as CodeWScope);
if(ReferenceEquals(this, obj))
return true;
return obj.GetType() == typeof(CodeWScope) && Equals((CodeWScope)obj);
}

/// <summary>
/// Returns a hash code for this instance.
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
unchecked
{
return (base.GetHashCode()*397) ^ (Scope != null ? Scope.GetHashCode() : 0);
return ((Value != null ? Value.GetHashCode() : 0)*397) ^ (Scope != null ? Scope.GetHashCode() : 0);
}
}

/// <summary>
/// Implements the operator ==.
/// Implements the operator ==.
/// </summary>
/// <param name = "left">The left.</param>
/// <param name = "right">The right.</param>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static bool operator ==(CodeWScope left, CodeWScope right)
{
return Equals(left, right);
}

/// <summary>
/// Implements the operator !=.
/// Implements the operator !=.
/// </summary>
/// <param name = "left">The left.</param>
/// <param name = "right">The right.</param>
/// <param name="left">The left.</param>
/// <param name="right">The right.</param>
/// <returns>The result of the operator.</returns>
public static bool operator !=(CodeWScope left, CodeWScope right)
{
Expand Down
1 change: 0 additions & 1 deletion source/MongoDB/MongoRegex.cs
@@ -1,5 +1,4 @@
using System;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
Expand Down
1 change: 1 addition & 0 deletions tools/Benchmark/Benchmark.csproj
Expand Up @@ -51,6 +51,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
Expand Down

0 comments on commit d0784c3

Please sign in to comment.