Skip to content

Commit f1dc278

Browse files
committed
Fix build error for some platforms.
1 parent 7b32c3a commit f1dc278

16 files changed

Lines changed: 293 additions & 182 deletions

src/MsgPack/Timestamp.Calculation.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,25 @@
2828
#else
2929
using System.Diagnostics.Contracts;
3030
#endif // CORE_CLR || UNITY || NETSTANDARD1_1
31-
#if !NET35
31+
#if !NET35 && !UNITY
32+
#if !WINDOWS_PHONE
33+
#if !UNITY || MSGPACK_UNITY_FULL
3234
using System.Numerics;
33-
#endif // !NET35
35+
#endif // !WINDOWS_PHONE
36+
#endif // !UNITY || MSGPACK_UNITY_FULL
37+
#endif // !NET35 && !UNITY
3438

3539
namespace MsgPack
3640
{
3741
partial struct Timestamp
3842
{
39-
#if !NET35
43+
#if !NET35 && !UNITY
44+
#if !WINDOWS_PHONE
45+
#if !UNITY || MSGPACK_UNITY_FULL
4046
private static readonly BigInteger NanoToSecondsAsBigInteger = new BigInteger( 1000 * 1000 * 1000 );
41-
#endif // !NET35
47+
#endif // !WINDOWS_PHONE
48+
#endif // !UNITY || MSGPACK_UNITY_FULL
49+
#endif // !NET35 && !UNITY
4250

4351
/// <summary>
4452
/// Adds a specified <see cref="TimeSpan"/> to this instance.
@@ -88,7 +96,10 @@ public Timestamp Subtract( TimeSpan offset )
8896
return this.Add( -offset );
8997
}
9098

91-
#if !NET35
99+
#if !NET35 && !UNITY
100+
#if !WINDOWS_PHONE
101+
#if !UNITY || MSGPACK_UNITY_FULL
102+
92103
/// <summary>
93104
/// Adds a specified nanoseconds represented as a <see cref="BigInteger"/> from this instance.
94105
/// </summary>
@@ -158,7 +169,10 @@ public BigInteger Subtract( Timestamp other )
158169

159170
return seconds * SecondsToNanos + nanos;
160171
}
161-
#endif // !NET35
172+
173+
#endif // !WINDOWS_PHONE
174+
#endif // !UNITY || MSGPACK_UNITY_FULL
175+
#endif // !NET35 && !UNITY
162176

163177
/// <summary>
164178
/// Calculates a <see cref="Timestamp"/> with specified <see cref="Timestamp"/> and an offset represented as <see cref="TimeSpan"/>.
@@ -182,7 +196,9 @@ public BigInteger Subtract( Timestamp other )
182196
return value.Subtract( offset );
183197
}
184198

185-
#if !NET35
199+
#if !NET35 && !UNITY
200+
#if !WINDOWS_PHONE
201+
#if !UNITY || MSGPACK_UNITY_FULL
186202

187203
/// <summary>
188204
/// Calculates a <see cref="Timestamp"/> with specified <see cref="Timestamp"/> and a nanoseconds offset represented as <see cref="BigInteger"/>.
@@ -216,6 +232,9 @@ public BigInteger Subtract( Timestamp other )
216232
{
217233
return left.Subtract( right );
218234
}
219-
#endif // !NET35
235+
236+
#endif // !WINDOWS_PHONE
237+
#endif // !UNITY || MSGPACK_UNITY_FULL
238+
#endif // !NET35 && !UNITY
220239
}
221240
}

src/MsgPack/Timestamp.Properties.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,11 @@ public static Timestamp UtcNow
489489
{
490490
var now = DateTimeOffset.UtcNow;
491491
return new Timestamp(
492-
#if !NET35 && !NET45 && !NETSTANDARD1_1
492+
#if !NET35 && !NET45 && !NETSTANDARD1_1 && !UNITY && !SILVERLIGHT
493493
now.ToUnixTimeSeconds(),
494-
#else // !NET35 && !NET45 && !NETSTANDARD1_1
494+
#else // !NET35 && !NET45 && !NETSTANDARD1_1 && !UNITY && !SILVERLIGHT
495495
( now.Ticks / TimeSpan.TicksPerSecond ) - UnixEpochInSeconds,
496-
#endif // !NET35 && !NET45 && !NETSTANDARD1_1
496+
#endif // !NET35 && !NET45 && !NETSTANDARD1_1 && !UNITY && !SILVERLIGHT
497497
unchecked( ( int )( now.Ticks % 10000000 * 100 ) )
498498
);
499499
}

src/MsgPack/Timestamp.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private static int ToDaysOffsetFromNewYear( int month, int day, bool isLeapYear
169169
return result;
170170
}
171171

172-
#if NETSTANDARD1_1 || NETSTANDARD1_3
172+
#if NETSTANDARD1_1 || NETSTANDARD1_3 || SILVERLIGHT
173173

174174
// Slow alternative
175175
internal static long DivRem( long dividend, long divisor, out long remainder )
@@ -178,14 +178,14 @@ internal static long DivRem( long dividend, long divisor, out long remainder )
178178
return dividend / divisor;
179179
}
180180

181-
#else // NETSTANDARD1_1 || NETSTANDARD1_3
181+
#else // NETSTANDARD1_1 || NETSTANDARD1_3 || SILVERLIGHT
182182

183183
internal static long DivRem( long dividend, long divisor, out long remainder )
184184
{
185185
return Math.DivRem( dividend, divisor, out remainder );
186186
}
187187

188-
#endif // NETSTANDARD1_1 || NETSTANDARD1_3
188+
#endif // NETSTANDARD1_1 || NETSTANDARD1_3 || SILVERLIGHT
189189

190190
internal struct Value
191191
{

test/MsgPack.UnitTest/Serialization/TimestampSerializationTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
using System;
2222
using System.IO;
23+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
2324
using System.Runtime.InteropServices.ComTypes;
25+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
2426

2527
using MsgPack.Serialization.DefaultSerializers;
2628

@@ -51,7 +53,9 @@ private static void TestSerializationCore( SerializationContext context, DateTim
5153
Timestamp = now,
5254
DateTime = dateTimeNow.AddSeconds( 1 ).UtcDateTime,
5355
DateTimeOffset = dateTimeNow.AddSeconds( 2 ),
56+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
5457
FileTime = now.Add( TimeSpan.FromSeconds( 3 ) ).ToDateTime().ToWin32FileTimeUtc()
58+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
5559
};
5660

5761
using ( var buffer = new MemoryStream() )
@@ -117,23 +121,29 @@ private static void TestSerializationCore( SerializationContext context, DateTim
117121
Assert.That( result.Timestamp, Is.EqualTo( new Timestamp( now.UnixEpochSecondsPart, now.NanosecondsPart / 100 * 100 ) ) );
118122
Assert.That( result.DateTime, Is.EqualTo( now.ToDateTime().AddSeconds( 1 ) ) );
119123
Assert.That( result.DateTimeOffset, Is.EqualTo( now.ToDateTimeOffset().AddSeconds( 2 ) ) );
124+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
120125
Assert.That( result.FileTime, Is.EqualTo( now.Add( TimeSpan.FromSeconds( 3 ).Subtract( TimeSpan.FromTicks( now.NanosecondsPart % 100 ) ) ).ToDateTime().ToWin32FileTimeUtc() ) );
126+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
121127
break;
122128
}
123129
case DateTimeConversionMethod.UnixEpoc:
124130
{
125131
Assert.That( result.Timestamp, Is.EqualTo( new Timestamp( now.UnixEpochSecondsPart, now.NanosecondsPart / 1000000 * 1000000 ) ) );
126132
Assert.That( result.DateTime, Is.EqualTo( now.ToDateTime().AddSeconds( 1 ).Subtract( TimeSpan.FromTicks( now.NanosecondsPart / 100 % 10000 ) ) ) );
127133
Assert.That( result.DateTimeOffset, Is.EqualTo( now.ToDateTimeOffset().AddSeconds( 2 ).Subtract( TimeSpan.FromTicks( now.NanosecondsPart / 100 % 10000 ) ) ) );
134+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
128135
Assert.That( result.FileTime, Is.EqualTo( now.Add( TimeSpan.FromSeconds( 3 ).Subtract( TimeSpan.FromTicks( now.NanosecondsPart / 100 % 10000 ) ) ).ToDateTime().ToWin32FileTimeUtc() ) );
136+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
129137
break;
130138
}
131139
case DateTimeConversionMethod.Timestamp:
132140
{
133141
Assert.That( result.Timestamp, Is.EqualTo( now ) );
134142
Assert.That( result.DateTime, Is.EqualTo( now.ToDateTime().AddSeconds( 1 ) ) );
135143
Assert.That( result.DateTimeOffset, Is.EqualTo( now.ToDateTimeOffset().AddSeconds( 2 ) ) );
144+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
136145
Assert.That( result.FileTime, Is.EqualTo( now.Add( TimeSpan.FromSeconds( 3 ) ).ToDateTime().ToWin32FileTimeUtc() ) );
146+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
137147
break;
138148
}
139149
}
@@ -230,23 +240,29 @@ private static void TestDeserializationCore( DateTimeConversionMethod kind )
230240
Assert.That( result.Timestamp, Is.EqualTo( new Timestamp( now.UnixEpochSecondsPart, now.NanosecondsPart / 100 * 100 ) ) );
231241
Assert.That( result.DateTime, Is.EqualTo( now.ToDateTime().AddSeconds( 1 ) ) );
232242
Assert.That( result.DateTimeOffset, Is.EqualTo( now.ToDateTimeOffset().AddSeconds( 2 )) );
243+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
233244
Assert.That( result.FileTime, Is.EqualTo( now.Add( TimeSpan.FromSeconds( 3 ).Subtract( TimeSpan.FromTicks( now.NanosecondsPart % 100 ) ) ).ToDateTime().ToWin32FileTimeUtc() ) );
245+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
234246
break;
235247
}
236248
case DateTimeConversionMethod.UnixEpoc:
237249
{
238250
Assert.That( result.Timestamp, Is.EqualTo( new Timestamp( now.UnixEpochSecondsPart, now.NanosecondsPart / 1000000 * 1000000 ) ) );
239251
Assert.That( result.DateTime, Is.EqualTo( now.ToDateTime().AddSeconds( 1 ).Subtract( TimeSpan.FromTicks( now.NanosecondsPart / 100 % 10000 ) ) ) );
240252
Assert.That( result.DateTimeOffset, Is.EqualTo( now.ToDateTimeOffset().AddSeconds( 2 ).Subtract( TimeSpan.FromTicks( now.NanosecondsPart / 100 % 10000 ) ) ) );
253+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
241254
Assert.That( result.FileTime, Is.EqualTo( now.Add( TimeSpan.FromSeconds( 3 ).Subtract( TimeSpan.FromTicks( now.NanosecondsPart / 100 % 10000 ) ) ).ToDateTime().ToWin32FileTimeUtc() ) );
255+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
242256
break;
243257
}
244258
case DateTimeConversionMethod.Timestamp:
245259
{
246260
Assert.That( result.Timestamp, Is.EqualTo( now ) );
247261
Assert.That( result.DateTime, Is.EqualTo( now.ToDateTime().AddSeconds( 1 ) ) );
248262
Assert.That( result.DateTimeOffset, Is.EqualTo( now.ToDateTimeOffset().AddSeconds( 2 ) ) );
263+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
249264
Assert.That( result.FileTime, Is.EqualTo( now.Add( TimeSpan.FromSeconds( 3 ) ).ToDateTime().ToWin32FileTimeUtc() ) );
265+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
250266
break;
251267
}
252268
}
@@ -274,15 +290,21 @@ public void TestDeserialization_FromUnixEpoc()
274290

275291
public class ClassHasTimestamp
276292
{
293+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
277294
internal const int MemberCount = 4;
295+
#else // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
296+
internal const int MemberCount = 3;
297+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
278298

279299
[MessagePackMember( 0 )]
280300
public Timestamp Timestamp { get; set; }
281301
[MessagePackMember( 1 )]
282302
public DateTime DateTime { get; set; }
283303
[MessagePackMember( 2 )]
284304
public DateTimeOffset DateTimeOffset { get; set; }
305+
#if ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
285306
[MessagePackMember( 3 )]
286307
public FILETIME FileTime { get; set; }
308+
#endif // ( !SILVERLIGHT || WINDOWS_PHONE ) && !XAMARIN && !UNITY && !UNITY
287309
}
288310
}

test/MsgPack.UnitTest/TimestampTest.Calculation.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121

2222
using System;
2323
using System.Globalization;
24-
#if !NET35
24+
#if !NET35 && !UNITY
25+
#if !WINDOWS_PHONE
26+
#if !UNITY || MSGPACK_UNITY_FULL
2527
using System.Numerics;
26-
#endif // !NET35
28+
#endif // !NET35 && !UNITY
29+
#endif // !WINDOWS_PHONE
30+
#endif // !UNITY || MSGPACK_UNITY_FULL
31+
2732
#if !MSTEST
2833
using NUnit.Framework;
2934
#else
@@ -446,7 +451,9 @@ public void TestSubtractionOperator_TimeSpan_MinMinus1Tick_Overflow()
446451
Assert.Throws<OverflowException>( () => { var x = @base - operand; } );
447452
}
448453

449-
#if !NET35
454+
#if !NET35 && !UNITY
455+
#if !WINDOWS_PHONE
456+
#if !UNITY || MSGPACK_UNITY_FULL
450457

451458
[Test]
452459
public void TestAdd_BigInteger_Same()
@@ -983,6 +990,8 @@ public void TestSubtractionOperator_Timstamp_MinMax()
983990
}
984991

985992

986-
#endif // !NET35
993+
#endif // !NET35 && !UNITY
994+
#endif // !WINDOWS_PHONE
995+
#endif // !UNITY || MSGPACK_UNITY_FULL
987996
}
988997
}

test/MsgPack.UnitTest/TimestampTest.Calculation.tt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@
2929

3030
using System;
3131
using System.Globalization;
32-
#if !NET35
32+
#if !NET35 && !UNITY
33+
#if !WINDOWS_PHONE
34+
#if !UNITY || MSGPACK_UNITY_FULL
3335
using System.Numerics;
34-
#endif // !NET35
36+
#endif // !NET35 && !UNITY
37+
#endif // !WINDOWS_PHONE
38+
#endif // !UNITY || MSGPACK_UNITY_FULL
39+
3540
#if !MSTEST
3641
using NUnit.Framework;
3742
#else
@@ -73,7 +78,9 @@ WriteSubtractTestsOverflow( "TimeSpan", "MinMinus1Sec", Int64.MinValue, 9999999
7378
WriteSubtractTestsOverflow( "TimeSpan", "MaxPlus1Tick", Int64.MaxValue, 999999900, "TimeSpan.FromTicks( -1 )" );
7479
WriteSubtractTestsOverflow( "TimeSpan", "MinMinus1Tick", Int64.MinValue, 000000099, "TimeSpan.FromTicks( 1 )" );
7580
#>
76-
#if !NET35
81+
#if !NET35 && !UNITY
82+
#if !WINDOWS_PHONE
83+
#if !UNITY || MSGPACK_UNITY_FULL
7784

7885
<#
7986
// Timestamp + BigInteger -> Timestamp
@@ -112,7 +119,9 @@ WriteDifferentiateTests( "MaxMin", Int64.MaxValue, 999999999, Int64.MinValue,
112119
WriteDifferentiateTests( "MinMax", Int64.MinValue, 0, Int64.MaxValue, 999999999, "new BigInteger( Int64.MinValue ) * 1000000000 - new BigInteger( Int64.MaxValue ) * 1000000000 - 999999999" );
113120
#>
114121

115-
#endif // !NET35
122+
#endif // !NET35 && !UNITY
123+
#endif // !WINDOWS_PHONE
124+
#endif // !UNITY || MSGPACK_UNITY_FULL
116125
}
117126
}
118127
<#+

0 commit comments

Comments
 (0)