From 6716432ca60b1ad53b20165d9bc29f853fcf1deb Mon Sep 17 00:00:00 2001 From: csharptest Date: Sun, 14 Oct 2012 18:47:48 -0500 Subject: [PATCH] Last (hopefully) changes to pre-processing directives --- .../Microsoft.VisualStudio.TestTools.cs | 2 +- .../SerializableAttribute.cs | 2 +- src/ProtocolBuffers/CodedInputStream.cs | 17 +------------- src/ProtocolBuffers/CodedOutputStream.cs | 22 +------------------ src/ProtocolBuffers/CustomSerialization.cs | 2 +- src/ProtocolBuffers/FrameworkPortability.cs | 22 +++++++++++++++++++ .../ProtocolBuffersLite.Test.csproj | 4 +++- .../ProtocolBuffersLiteMixed.Test.csproj | 4 +++- .../SerializableAttribute.cs | 12 ---------- .../SerializableLiteTest.cs | 2 +- 10 files changed, 34 insertions(+), 55 deletions(-) delete mode 100644 src/ProtocolBuffersLite.Test/SerializableAttribute.cs diff --git a/lib/NUnit-config/Microsoft.VisualStudio.TestTools.cs b/lib/NUnit-config/Microsoft.VisualStudio.TestTools.cs index 2726299689..fd151dae8b 100644 --- a/lib/NUnit-config/Microsoft.VisualStudio.TestTools.cs +++ b/lib/NUnit-config/Microsoft.VisualStudio.TestTools.cs @@ -1,6 +1,6 @@  using System; -#if !SILVERLIGHT && !COMPACT_FRAMEWORK +#if CLIENTPROFILE namespace Microsoft.VisualStudio.TestTools.UnitTesting { [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)] diff --git a/src/ProtocolBuffers.Test/SerializableAttribute.cs b/src/ProtocolBuffers.Test/SerializableAttribute.cs index 04fcdcbadd..0553762bcf 100644 --- a/src/ProtocolBuffers.Test/SerializableAttribute.cs +++ b/src/ProtocolBuffers.Test/SerializableAttribute.cs @@ -1,4 +1,4 @@ -#if SILVERLIGHT +#if NOSERIALIZABLE && !COMPACT_FRAMEWORK namespace System { diff --git a/src/ProtocolBuffers/CodedInputStream.cs b/src/ProtocolBuffers/CodedInputStream.cs index 230c585cfa..e4d690b5db 100644 --- a/src/ProtocolBuffers/CodedInputStream.cs +++ b/src/ProtocolBuffers/CodedInputStream.cs @@ -231,22 +231,7 @@ namespace Google.ProtocolBuffers /// public bool ReadDouble(ref double value) { -#if SILVERLIGHT || COMPACT_FRAMEWORK - if (BitConverter.IsLittleEndian && 8 <= bufferSize - bufferPos) - { - value = BitConverter.ToDouble(buffer, bufferPos); - bufferPos += 8; - } - else - { - byte[] rawBytes = ReadRawBytes(8); - if (!BitConverter.IsLittleEndian) - ByteArray.Reverse(rawBytes); - value = BitConverter.ToDouble(rawBytes, 0); - } -#else - value = BitConverter.Int64BitsToDouble((long) ReadRawLittleEndian64()); -#endif + value = FrameworkPortability.Int64ToDouble((long) ReadRawLittleEndian64()); return true; } diff --git a/src/ProtocolBuffers/CodedOutputStream.cs b/src/ProtocolBuffers/CodedOutputStream.cs index f4d637c1ec..b6a501c496 100644 --- a/src/ProtocolBuffers/CodedOutputStream.cs +++ b/src/ProtocolBuffers/CodedOutputStream.cs @@ -496,27 +496,7 @@ namespace Google.ProtocolBuffers /// public void WriteDoubleNoTag(double value) { -#if SILVERLIGHT || COMPACT_FRAMEWORK - byte[] rawBytes = BitConverter.GetBytes(value); - if (!BitConverter.IsLittleEndian) - ByteArray.Reverse(rawBytes); - - if (limit - position >= 8) - { - buffer[position++] = rawBytes[0]; - buffer[position++] = rawBytes[1]; - buffer[position++] = rawBytes[2]; - buffer[position++] = rawBytes[3]; - buffer[position++] = rawBytes[4]; - buffer[position++] = rawBytes[5]; - buffer[position++] = rawBytes[6]; - buffer[position++] = rawBytes[7]; - } - else - WriteRawBytes(rawBytes, 0, 8); -#else - WriteRawLittleEndian64((ulong) BitConverter.DoubleToInt64Bits(value)); -#endif + WriteRawLittleEndian64((ulong)FrameworkPortability.DoubleToInt64(value)); } /// diff --git a/src/ProtocolBuffers/CustomSerialization.cs b/src/ProtocolBuffers/CustomSerialization.cs index a1aee029c5..d39041130a 100644 --- a/src/ProtocolBuffers/CustomSerialization.cs +++ b/src/ProtocolBuffers/CustomSerialization.cs @@ -34,7 +34,7 @@ #endregion /* - * This entire source file is not supported on the Silverlight platform + * This entire source file is not supported on some platform */ #if !NOSERIALIZABLE diff --git a/src/ProtocolBuffers/FrameworkPortability.cs b/src/ProtocolBuffers/FrameworkPortability.cs index 78b7db31dd..fee8fbace0 100644 --- a/src/ProtocolBuffers/FrameworkPortability.cs +++ b/src/ProtocolBuffers/FrameworkPortability.cs @@ -63,6 +63,28 @@ namespace Google.ProtocolBuffers get { return CultureInfo.InvariantCulture; } } + internal static double Int64ToDouble(long value) + { +#if CLIENTPROFILE + return BitConverter.Int64BitsToDouble(value); +#else + double[] arresult = new double[1]; + Buffer.BlockCopy(new[] { value }, 0, arresult, 0, 8); + return arresult[0]; +#endif + } + + internal static long DoubleToInt64(double value) + { +#if CLIENTPROFILE + return BitConverter.DoubleToInt64Bits(value); +#else + long[] arresult = new long[1]; + Buffer.BlockCopy(new[] { value }, 0, arresult, 0, 8); + return arresult[0]; +#endif + } + internal static bool TryParseInt32(string text, out int number) { return TryParseInt32(text, NumberStyles.Any, InvariantCulture, out number); diff --git a/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj b/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj index acabfd1814..353e5cdb96 100644 --- a/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj +++ b/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj @@ -69,6 +69,9 @@ Properties\AssemblyInfo.cs + + SerializableAttribute.cs + TestRpcForMimeTypes.cs @@ -80,7 +83,6 @@ - diff --git a/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj b/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj index db2c8eb4bf..f793593bb0 100644 --- a/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj +++ b/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj @@ -69,6 +69,9 @@ Properties\AssemblyInfo.cs + + SerializableAttribute.cs + @@ -76,7 +79,6 @@ - diff --git a/src/ProtocolBuffersLite.Test/SerializableAttribute.cs b/src/ProtocolBuffersLite.Test/SerializableAttribute.cs deleted file mode 100644 index 04fcdcbadd..0000000000 --- a/src/ProtocolBuffersLite.Test/SerializableAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -#if SILVERLIGHT - -namespace System -{ - [AttributeUsage(AttributeTargets.Class)] - public class SerializableAttribute : Attribute - { - public SerializableAttribute () : base() { } - } -} - -#endif diff --git a/src/ProtocolBuffersLite.Test/SerializableLiteTest.cs b/src/ProtocolBuffersLite.Test/SerializableLiteTest.cs index 5049f30a7d..3efb917965 100644 --- a/src/ProtocolBuffersLite.Test/SerializableLiteTest.cs +++ b/src/ProtocolBuffersLite.Test/SerializableLiteTest.cs @@ -1,5 +1,5 @@ using System; -#if !SILVERLIGHT && !COMPACT_FRAMEWORK +#if !NOSERIALIZABLE using System.Collections.Generic; using System.IO; using System.Runtime.Serialization;