THRIFT-1037 Proposed changes to support Silverlight, Windows Phone and AsyncCTP v3
Patch: Damian Mehers & Jens Geyer

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1211880 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/csharp/src/Protocol/TBinaryProtocol.cs b/lib/csharp/src/Protocol/TBinaryProtocol.cs
index 4b3980e..e6b69d6 100644
--- a/lib/csharp/src/Protocol/TBinaryProtocol.cs
+++ b/lib/csharp/src/Protocol/TBinaryProtocol.cs
@@ -201,7 +201,12 @@
 
 		public override void WriteDouble(double d)
 		{
+#if !SILVERLIGHT
 			WriteI64(BitConverter.DoubleToInt64Bits(d));
+#else
+            var bytes = BitConverter.GetBytes(d);
+            WriteI64(BitConverter.ToInt64(bytes, 0));
+#endif
 		}
 
 		public override void WriteBinary(byte[] b)
@@ -348,7 +353,13 @@
 
 		public override double ReadDouble()
 		{
+#if !SILVERLIGHT
 			return BitConverter.Int64BitsToDouble(ReadI64());
+#else
+            var value = ReadI64();
+            var bytes = BitConverter.GetBytes(value);
+            return BitConverter.ToDouble(bytes, 0);
+#endif
 		}
 
 		public void SetReadLength(int readLength)
@@ -382,7 +393,7 @@
 			CheckReadLength(size);
 			byte[] buf = new byte[size];
 			trans.ReadAll(buf, 0, size);
-			return Encoding.UTF8.GetString(buf);
+			return Encoding.UTF8.GetString(buf, 0, buf.Length);
 		}
 
 		private int ReadAll(byte[] buf, int off, int len)