-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSilverlightCompatibility.cs
88 lines (76 loc) · 2.35 KB
/
SilverlightCompatibility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* **************************************************************************
*
* Copyright (c) The IronSmalltalk Project.
*
* This source code is subject to terms and conditions of the
* license agreement found in the solution directory.
* See: $(SolutionDir)\License.htm ... in the root of this distribution.
* By using this source code in any fashion, you are agreeing
* to be bound by the terms of the license agreement.
*
* You must not remove this notice, or any other, from this software.
*
* **************************************************************************
*/
using System;
using System.Collections.Generic;
#if SILVERLIGHT
namespace System
{
/// <summary>
/// The serializable attribute.
/// </summary>
public class SerializableAttribute : Attribute
{
}
/// <summary>
/// Non serializable attribute.
/// </summary>
public class NonSerializedAttribute : Attribute
{
}
}
namespace System.Collections.Concurrent
{
public class ConcurrentDictionary<TKey, TValue> : Dictionary<TKey, TValue>
{
public ConcurrentDictionary()
{
}
public ConcurrentDictionary(int concurrencyLevel, int capacity, IEqualityComparer<TKey> comparer)
: base(capacity, comparer)
{
}
public TValue GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)
{
TValue value;
if (!this.TryGetValue(key, out value))
{
value = valueFactory(key);
this.Add(key, value);
}
return value;
}
public bool TryRemove(TKey key, out TValue value)
{
if (this.TryGetValue(key, out value))
{
this.Remove(key);
return true;
}
return false;
}
public bool TryUpdate(TKey key, TValue newValue, TValue comparisonValue)
{
if (!this.ContainsKey(key))
return false;
IEqualityComparer<TValue> comparer = (IEqualityComparer<TValue>)EqualityComparer<TValue>.Default;
if (!comparer.Equals(this[key], comparisonValue))
return false;
this[key] = newValue;
return true;
}
}
}
#endif