Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix missing System.Xml reference.

Make CodeWScope not longer depend on Code.
Add fix some more failing XmlSerializer tests.
  • Loading branch information...
commit d0784c3eac6fc80d60a9ffd945717e5800a2bc10 1 parent 7180367
@lanwin lanwin authored
View
1  examples/Simple/Simple.csproj
@@ -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" />
View
7 examples/SimpleVB/SimpleVB.vbproj
@@ -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" />
@@ -71,9 +72,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <Folder Include="My Project\" />
- </ItemGroup>
- <ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
@@ -90,5 +88,8 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
+ <ItemGroup>
+ <Folder Include="My Project\" />
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
</Project>
View
1  source/MongoDB.GridFS.Tests/MongoDB.GridFS.Tests.csproj
@@ -59,6 +59,7 @@
<HintPath>..\..\redist\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GridFileInfoTest.cs" />
View
1  source/MongoDB.GridFS/MongoDB.GridFS.csproj
@@ -62,6 +62,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\AssemblyInfoGlobal.cs">
View
27 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
@@ -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);
+ }
}
}
View
2  source/MongoDB.Tests/UnitTests/TestDBRef.cs
@@ -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);
View
38 source/MongoDB/Code.cs
@@ -1,7 +1,4 @@
using System;
-using System.Xml;
-using System.Xml.Schema;
-using System.Xml.Serialization;
using MongoDB.Util;
namespace MongoDB
@@ -9,7 +6,7 @@ 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.
@@ -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);
- }
}
}
View
49 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.
@@ -36,17 +35,23 @@ public CodeWScope(String code, Document 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)
{
@@ -54,45 +59,47 @@ public bool Equals(CodeWScope 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)
{
@@ -100,10 +107,10 @@ public override int GetHashCode()
}
/// <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)
{
View
1  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;
View
1  tools/Benchmark/Benchmark.csproj
@@ -51,6 +51,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.