11using JetBrains . Annotations ;
22
33using System ;
4+ using System . Collections ;
45using System . Collections . Generic ;
56
67namespace StringDB . Databases
@@ -9,9 +10,9 @@ namespace StringDB.Databases
910 /// A database which can only be read from.
1011 /// </summary>
1112 [ PublicAPI ]
12- public class WriteOnlyDatabase < TKey , TValue > : BaseDatabase < TKey , TValue >
13+ public class WriteOnlyDatabase < TKey , TValue >
14+ : IDatabase < TKey , TValue > , IDatabaseLayer < TKey , TValue >
1315 {
14- [ NotNull ] private readonly IDatabase < TKey , TValue > _database ;
1516 private readonly bool _disposeDatabase ;
1617
1718 /// <summary>
@@ -22,24 +23,42 @@ public class WriteOnlyDatabase<TKey, TValue> : BaseDatabase<TKey, TValue>
2223 public WriteOnlyDatabase ( [ NotNull ] IDatabase < TKey , TValue > database , bool disposeDatabase = true )
2324 {
2425 _disposeDatabase = disposeDatabase ;
25- _database = database ;
26+ InnerDatabase = database ;
2627 }
2728
2829 /// <inheritdoc/>
29- public override void Dispose ( )
30+ [ NotNull ] public IDatabase < TKey , TValue > InnerDatabase { get ; }
31+
32+ /// <inheritdoc/>
33+ public void Dispose ( )
3034 {
3135 if ( _disposeDatabase )
3236 {
33- _database . Dispose ( ) ;
37+ InnerDatabase . Dispose ( ) ;
3438 }
3539 }
3640
41+ private const string Error = "Reading is not supported." ;
42+
43+ /// <inheritdoc/>
44+ public TValue Get ( [ NotNull ] TKey key ) => throw new NotSupportedException ( Error ) ;
45+
46+ /// <inheritdoc/>
47+ public bool TryGet ( [ NotNull ] TKey key , [ CanBeNull ] out TValue value ) => throw new NotSupportedException ( Error ) ;
48+
49+ /// <inheritdoc/>
50+ public IEnumerable < ILazyLoader < TValue > > GetAll ( [ NotNull ] TKey key ) => throw new NotSupportedException ( Error ) ;
51+
52+ /// <inheritdoc/>
53+ public IEnumerator < KeyValuePair < TKey , ILazyLoader < TValue > > > GetEnumerator ( ) => throw new NotSupportedException ( Error ) ;
54+
55+ /// <inheritdoc/>
56+ public void Insert ( [ NotNull ] TKey key , [ NotNull ] TValue value ) => InnerDatabase . Insert ( key , value ) ;
57+
3758 /// <inheritdoc/>
38- public override void InsertRange ( params KeyValuePair < TKey , TValue > [ ] items )
39- => _database . InsertRange ( items ) ;
59+ public void InsertRange ( [ NotNull ] params KeyValuePair < TKey , TValue > [ ] items ) => InnerDatabase . InsertRange ( items ) ;
4060
4161 /// <inheritdoc/>
42- protected override IEnumerable < KeyValuePair < TKey , ILazyLoader < TValue > > > Evaluate ( )
43- => throw new NotSupportedException ( $ "Reading is not supported.") ;
62+ IEnumerator IEnumerable . GetEnumerator ( ) => InnerDatabase . GetEnumerator ( ) ;
4463 }
4564}
0 commit comments