@@ -7,11 +7,15 @@ open System.Collections.Generic
77#nowarn " 44" // This construct is deprecated. This F# library function has been renamed. Use 'isSome' instead
88
99[<StructuralEquality; NoComparison>]
10- type internal ValueStrength < 'T > =
10+ type internal ValueStrength < 'T when 'T : not struct > =
1111| Strongof 'T
12+ #if FX_ NO_ GENERIC_ WEAKREFERENCE
1213| Weakof WeakReference
14+ #else
15+ | Weakof WeakReference < 'T >
16+ #endif
1317
14- type internal AgedLookup < 'TKey , 'TValue >( keepStrongly : int , areSame , ? onStrongDiscard : ( 'TValue -> unit ), ? keepMax : int ) =
18+ type internal AgedLookup < 'TKey , 'TValue when 'TValue : not struct >( keepStrongly : int , areSame , ? onStrongDiscard : ( 'TValue -> unit ), ? keepMax : int ) =
1519/// The list of items stored. Youngest is at the end of the list.
1620/// The choice of order is somewhat aribtrary. If the other way then adding
1721/// items would be O(1) and removing O(N).
@@ -69,10 +73,15 @@ type internal AgedLookup<'TKey,'TValue>(keepStrongly:int, areSame, ?onStrongDisc
6973match valuewith
7074| Strong( value) -> yield ( key, value)
7175| Weak( weakReference) ->
76+ #if FX_ NO_ GENERIC_ WEAKREFERENCE
7277match weakReference.Targetwith
7378| null -> assert onStrongDiscard.IsNone; ()
7479| value-> yield key,( value:?> 'TValue) ]
75-
80+ #else
81+ match weakReference.TryGetTarget() with
82+ | false , _ -> assert onStrongDiscard.IsNone; ()
83+ | true , value-> yield key, value]
84+ #endif
7685
7786let AssignWithStrength ( newdata , discard1 ) =
7887let actualLength = List.length newdata
@@ -87,7 +96,11 @@ type internal AgedLookup<'TKey,'TValue>(keepStrongly:int, areSame, ?onStrongDisc
8796let handle =
8897if n< weakThreshholdthen
8998assert onStrongDiscard.IsNone; // it disappeared, we can't dispose
99+ #if FX_ NO_ GENERIC_ WEAKREFERENCE
90100 Weak( WeakReference( v))
101+ #else
102+ Weak( WeakReference<_>( v))
103+ #endif
91104else
92105 Strong( v)
93106 k, handle)
@@ -136,7 +149,7 @@ type internal AgedLookup<'TKey,'TValue>(keepStrongly:int, areSame, ?onStrongDisc
136149
137150
138151
139- type internal MruCache < 'TKey , 'TValue >( keepStrongly , compute , areSame , ? isStillValid : 'TKey * 'TValue -> bool , ? areSameForSubsumption , ? logComputedNewValue , ? logUsedCachedValue , ? onStrongDiscard , ? keepMax ) =
152+ type internal MruCache < 'TKey , 'TValue when 'TValue : not struct >( keepStrongly , compute , areSame , ? isStillValid : 'TKey * 'TValue -> bool , ? areSameForSubsumption , ? logComputedNewValue , ? logUsedCachedValue , ? onStrongDiscard , ? keepMax ) =
140153
141154/// Default behavior of areSameForSubsumption function is areSame
142155let areSameForSubsumption = defaultArg areSameForSubsumption areSame