@@ -44,9 +44,13 @@ partial void SetValueManager (CreationOptions options)
44
44
public abstract partial class JniValueManager : ISetRuntime , IDisposable {
45
45
46
46
public JniRuntime Runtime { get ; private set ; }
47
+ protected bool disposed = false ;
47
48
48
49
public virtual void OnSetRuntime ( JniRuntime runtime )
49
50
{
51
+ if ( disposed )
52
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
53
+
50
54
Runtime = runtime ;
51
55
}
52
56
@@ -58,6 +62,7 @@ public void Dispose ()
58
62
59
63
protected virtual void Dispose ( bool disposing )
60
64
{
65
+ disposed = true ;
61
66
}
62
67
63
68
public abstract void WaitForGCBridgeProcessing ( ) ;
@@ -123,6 +128,9 @@ public int GetJniIdentityHashCode (JniObjectReference reference)
123
128
124
129
public virtual void DisposePeer ( IJavaPeerable value )
125
130
{
131
+ if ( disposed )
132
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
133
+
126
134
if ( value == null )
127
135
throw new ArgumentNullException ( nameof ( value ) ) ;
128
136
@@ -135,6 +143,9 @@ public virtual void DisposePeer (IJavaPeerable value)
135
143
136
144
void DisposePeer ( JniObjectReference h , IJavaPeerable value )
137
145
{
146
+ if ( disposed )
147
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
148
+
138
149
value . Disposed ( ) ;
139
150
RemovePeer ( value ) ;
140
151
var o = Runtime . ObjectReferenceManager ;
@@ -162,6 +173,9 @@ void DisposePeer (JniObjectReference h, IJavaPeerable value)
162
173
163
174
public virtual void DisposePeerUnlessReferenced ( IJavaPeerable value )
164
175
{
176
+ if ( disposed )
177
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
178
+
165
179
if ( value == null )
166
180
throw new ArgumentNullException ( nameof ( value ) ) ;
167
181
@@ -180,6 +194,9 @@ public virtual void DisposePeerUnlessReferenced (IJavaPeerable value)
180
194
181
195
public object PeekValue ( JniObjectReference reference )
182
196
{
197
+ if ( disposed )
198
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
199
+
183
200
if ( ! reference . IsValid )
184
201
return null ;
185
202
@@ -237,6 +254,9 @@ static Type GetPeerType (Type type)
237
254
238
255
public virtual IJavaPeerable CreatePeer ( ref JniObjectReference reference , JniObjectReferenceOptions transfer , Type targetType )
239
256
{
257
+ if ( disposed )
258
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
259
+
240
260
targetType = targetType ?? typeof ( JavaObject ) ;
241
261
targetType = GetPeerType ( targetType ) ;
242
262
@@ -311,6 +331,9 @@ static ConstructorInfo GetActivationConstructor (Type type)
311
331
312
332
public object CreateValue ( ref JniObjectReference reference , JniObjectReferenceOptions options , Type targetType = null )
313
333
{
334
+ if ( disposed )
335
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
336
+
314
337
if ( ! reference . IsValid )
315
338
return null ;
316
339
@@ -337,6 +360,9 @@ public object CreateValue (ref JniObjectReference reference, JniObjectReferenceO
337
360
338
361
public T CreateValue < T > ( ref JniObjectReference reference , JniObjectReferenceOptions options , Type targetType = null )
339
362
{
363
+ if ( disposed )
364
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
365
+
340
366
if ( ! reference . IsValid )
341
367
return default ( T ) ;
342
368
@@ -374,6 +400,9 @@ internal Type GetRuntimeType (JniObjectReference reference)
374
400
375
401
public object GetValue ( ref JniObjectReference reference , JniObjectReferenceOptions options , Type targetType = null )
376
402
{
403
+ if ( disposed )
404
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
405
+
377
406
if ( ! reference . IsValid )
378
407
return null ;
379
408
@@ -435,6 +464,9 @@ public T GetValue<T> (ref JniObjectReference reference, JniObjectReferenceOption
435
464
436
465
public JniValueMarshaler < T > GetValueMarshaler < T > ( )
437
466
{
467
+ if ( disposed )
468
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
469
+
438
470
var m = GetValueMarshaler ( typeof ( T ) ) ;
439
471
var r = m as JniValueMarshaler < T > ;
440
472
if ( r != null )
@@ -449,6 +481,9 @@ public JniValueMarshaler<T> GetValueMarshaler<T>()
449
481
450
482
public JniValueMarshaler GetValueMarshaler ( Type type )
451
483
{
484
+ if ( disposed )
485
+ throw new ObjectDisposedException ( GetType ( ) . Name ) ;
486
+
452
487
if ( type == null )
453
488
throw new ArgumentNullException ( "type" ) ;
454
489
var info = type . GetTypeInfo ( ) ;
0 commit comments