|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | 1 | using System.Runtime.CompilerServices; |
4 | 2 | using Platform.Disposables; |
5 | 3 |
|
6 | 4 | #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member |
| 5 | +#pragma warning disable CA1063 // Implement IDisposable Correctly |
7 | 6 |
|
8 | 7 | namespace Platform.Data.Doublets.Decorators |
9 | 8 | { |
10 | | - public abstract class LinksDisposableDecoratorBase<TLink> : DisposableBase, ILinks<TLink> |
| 9 | + public abstract class LinksDisposableDecoratorBase<TLink> : LinksDecoratorBase<TLink>, ILinks<TLink>, System.IDisposable |
11 | 10 | { |
12 | | - private ILinks<TLink> _facade; |
13 | | - |
14 | | - public LinksConstants<TLink> Constants |
15 | | - { |
16 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
17 | | - get; |
18 | | - } |
19 | | - |
20 | | - public ILinks<TLink> Links |
| 11 | + protected class DisposableWithMultipleCallsAllowed : Disposable |
21 | 12 | { |
22 | 13 | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
23 | | - get; |
24 | | - } |
| 14 | + public DisposableWithMultipleCallsAllowed(Disposal disposal) : base(disposal) { } |
25 | 15 |
|
26 | | - public ILinks<TLink> Facade |
27 | | - { |
28 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
29 | | - get => _facade; |
30 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
31 | | - set |
| 16 | + protected override bool AllowMultipleDisposeCalls |
32 | 17 | { |
33 | | - _facade = value; |
34 | | - if (Links is LinksDecoratorBase<TLink> decorator) |
35 | | - { |
36 | | - decorator.Facade = value; |
37 | | - } |
38 | | - else if (Links is LinksDisposableDecoratorBase<TLink> disposableDecorator) |
39 | | - { |
40 | | - disposableDecorator.Facade = value; |
41 | | - } |
| 18 | + [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| 19 | + get => true; |
42 | 20 | } |
43 | 21 | } |
44 | 22 |
|
45 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
46 | | - protected LinksDisposableDecoratorBase(ILinks<TLink> links) |
47 | | - { |
48 | | - Links = links; |
49 | | - Constants = links.Constants; |
50 | | - Facade = this; |
51 | | - } |
52 | | - |
53 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
54 | | - public virtual TLink Count(IList<TLink> restrictions) => Links.Count(restrictions); |
55 | | - |
56 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
57 | | - public virtual TLink Each(Func<IList<TLink>, TLink> handler, IList<TLink> restrictions) => Links.Each(handler, restrictions); |
| 23 | + protected readonly DisposableWithMultipleCallsAllowed Disposable; |
58 | 24 |
|
59 | 25 | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
60 | | - public virtual TLink Create(IList<TLink> restrictions) => Links.Create(restrictions); |
| 26 | + protected LinksDisposableDecoratorBase(ILinks<TLink> links) : base(links) => Disposable = new DisposableWithMultipleCallsAllowed(Dispose); |
61 | 27 |
|
62 | 28 | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
63 | | - public virtual TLink Update(IList<TLink> restrictions, IList<TLink> substitution) => Links.Update(restrictions, substitution); |
| 29 | + ~LinksDisposableDecoratorBase() => Disposable.Destruct(); |
64 | 30 |
|
65 | 31 | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
66 | | - public virtual void Delete(IList<TLink> restrictions) => Links.Delete(restrictions); |
67 | | - |
68 | | - protected override bool AllowMultipleDisposeCalls |
69 | | - { |
70 | | - [MethodImpl(MethodImplOptions.AggressiveInlining)] |
71 | | - get => true; |
72 | | - } |
| 32 | + public void Dispose() => Disposable.Dispose(); |
73 | 33 |
|
74 | 34 | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
75 | | - protected override void Dispose(bool manual, bool wasDisposed) |
| 35 | + protected virtual void Dispose(bool manual, bool wasDisposed) |
76 | 36 | { |
77 | 37 | if (!wasDisposed) |
78 | 38 | { |
|
0 commit comments