@@ -43,28 +43,27 @@ public static FileLifecycleHooks ChainTo(this FileLifecycleHooks first, FileLife
43
43
44
44
class FileLifeCycleHookChain : FileLifecycleHooks
45
45
{
46
- private readonly FileLifecycleHooks [ ] hooks ;
46
+ private readonly FileLifecycleHooks _first ;
47
+ private readonly FileLifecycleHooks _second ;
47
48
48
- public FileLifeCycleHookChain ( params FileLifecycleHooks [ ] hooks )
49
+ public FileLifeCycleHookChain ( FileLifecycleHooks first , FileLifecycleHooks second )
49
50
{
50
- this . hooks = hooks ?? throw new ArgumentNullException ( nameof ( hooks ) ) ;
51
+ _first = first ?? throw new ArgumentNullException ( nameof ( first ) ) ;
52
+ _second = second ?? throw new ArgumentNullException ( nameof ( second ) ) ;
51
53
}
52
54
53
55
public override Stream OnFileOpened ( Stream underlyingStream , Encoding encoding )
54
56
{
55
- for ( int i = 0 ; i < hooks . Length ; i ++ )
56
- {
57
- underlyingStream = hooks [ i ] . OnFileOpened ( underlyingStream , encoding ) ;
58
- }
59
- return underlyingStream ;
57
+ var firstStreamResult = _first . OnFileOpened ( underlyingStream , encoding ) ;
58
+ var secondStreamResult = _second . OnFileOpened ( firstStreamResult , encoding ) ;
59
+
60
+ return secondStreamResult ;
60
61
}
61
62
62
63
public override void OnFileDeleting ( string path )
63
64
{
64
- for ( int i = 0 ; i < hooks . Length ; i ++ )
65
- {
66
- hooks [ i ] . OnFileDeleting ( path ) ;
67
- }
65
+ _first . OnFileDeleting ( path ) ;
66
+ _second . OnFileDeleting ( path ) ;
68
67
}
69
68
}
70
69
}
0 commit comments