Skip to content

Commit 31f5534

Browse files
committed
Unity iOS compatibility hacks
1 parent a695499 commit 31f5534

File tree

3 files changed

+76
-13
lines changed

3 files changed

+76
-13
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// DefaultEqualityComparer.cs
3+
//
4+
// Author:
5+
// Jim Borden <jim.borden@couchbase.com>
6+
//
7+
// Copyright (c) 2015 Couchbase, Inc All rights reserved.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// http://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//
21+
using System;
22+
23+
namespace System.Collections.Generic
24+
{
25+
//This class is needed for Unity iOS compatibility
26+
[Serializable]
27+
public sealed class DefaultComparer<T> : IEqualityComparer, IEqualityComparer <T> {
28+
29+
public int GetHashCode (T obj)
30+
{
31+
if (obj == null)
32+
return 0;
33+
return obj.GetHashCode ();
34+
}
35+
36+
public bool Equals (T x, T y)
37+
{
38+
if (x == null)
39+
return y == null;
40+
41+
return x.Equals (y);
42+
}
43+
44+
public int GetHashCode(object obj)
45+
{
46+
if (obj == null)
47+
return 0;
48+
49+
if (!(obj is T))
50+
throw new ArgumentException ("Argument is not compatible", "obj");
51+
52+
return GetHashCode ((T)obj);
53+
}
54+
}
55+
}
56+

System.Threading.Tasks.Net35.csproj

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,31 @@
66
<ProjectGuid>{DCB5D745-525C-46A1-BFC0-E12F87AB6165}</ProjectGuid>
77
<OutputType>Library</OutputType>
88
<RootNamespace>System.Threading.Tasks.Net35</RootNamespace>
9-
<ReleaseVersion>1.0.4</ReleaseVersion>
109
<AssemblyName>System.Threading.Tasks.Net35</AssemblyName>
1110
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
11+
<ReleaseVersion>1.0.4</ReleaseVersion>
12+
<UseMSBuildEngine>False</UseMSBuildEngine>
1213
</PropertyGroup>
1314
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14-
<DebugSymbols>true</DebugSymbols>
15+
<DebugSymbols>True</DebugSymbols>
1516
<DebugType>full</DebugType>
16-
<Optimize>false</Optimize>
17+
<Optimize>False</Optimize>
1718
<OutputPath>bin\Debug</OutputPath>
18-
<DefineConstants>DEBUG;NET_4_5;</DefineConstants>
19+
<DefineConstants>DEBUG;TRACE;NET_4_5;</DefineConstants>
1920
<ErrorReport>prompt</ErrorReport>
2021
<WarningLevel>4</WarningLevel>
21-
<ConsolePause>false</ConsolePause>
22-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
22+
<ConsolePause>False</ConsolePause>
23+
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
2324
</PropertyGroup>
2425
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25-
<Optimize>true</Optimize>
26+
<Optimize>True</Optimize>
2627
<OutputPath>bin\Release</OutputPath>
2728
<ErrorReport>prompt</ErrorReport>
2829
<WarningLevel>4</WarningLevel>
29-
<ConsolePause>false</ConsolePause>
30-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
30+
<ConsolePause>False</ConsolePause>
31+
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
3132
<DefineConstants>NET_4_5;</DefineConstants>
33+
<DebugType>none</DebugType>
3234
</PropertyGroup>
3335
<ItemGroup>
3436
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -95,6 +97,7 @@
9597
<Compile Include="System.Collections.Concurrent.Partitioners\ListPartitioner.cs" />
9698
<Compile Include="System.Collections.Concurrent.Partitioners\UserRangePartitioner.cs" />
9799
<Compile Include="System.Collections.Generic\GenericEqualityComparer.cs" />
100+
<Compile Include="System.Collections.Generic\DefaultEqualityComparer.cs" />
98101
</ItemGroup>
99102
<ItemGroup>
100103
<Folder Include="System.Collections.Concurrent\" />

System.Threading/CancellationTokenSource.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public class CancellationTokenSource : IDisposable
4444
int state;
4545
int currId = int.MinValue;
4646
ConcurrentDictionary<CancellationTokenRegistration, Action> callbacks;
47-
CancellationTokenRegistration[] linkedTokens;
47+
CancellationTokenRegistration[] linkedTokens
48+
{
49+
get { return (CancellationTokenRegistration[])_linkedTokens; }
50+
}
51+
object _linkedTokens;
4852

4953
ManualResetEvent handle;
5054

@@ -230,7 +234,7 @@ public static CancellationTokenSource CreateLinkedTokenSource (params Cancellati
230234
if (token.CanBeCanceled)
231235
registrations.Add (token.Register (action));
232236
}
233-
src.linkedTokens = registrations.ToArray ();
237+
src._linkedTokens = registrations.ToArray ();
234238

235239
return src;
236240
}
@@ -283,10 +287,10 @@ void Dispose (bool disposing)
283287

284288
void UnregisterLinkedTokens ()
285289
{
286-
var registrations = Interlocked.Exchange (ref linkedTokens, null);
290+
var registrations = Interlocked.Exchange (ref _linkedTokens, null);
287291
if (registrations == null)
288292
return;
289-
foreach (var linked in registrations)
293+
foreach (var linked in (CancellationTokenRegistration[])registrations)
290294
linked.Dispose ();
291295
}
292296

0 commit comments

Comments
 (0)