@@ -100,77 +100,99 @@ public bool Remove(string key)
100100
101101 lock ( state . Sync )
102102 {
103- BasisDebug . Log ( $ "removing lock for { state } ") ;
103+ BasisDebug . Log ( $ "removing lock for { key } ") ;
104104 return state . Owners . Remove ( key ) ;
105105 }
106106 }
107107
108108 public void Clear ( )
109109 {
110110 if ( ! States . TryGetValue ( Context , out var state ) )
111+ {
111112 return ;
113+ }
112114
113115 lock ( state . Sync )
116+ {
114117 state . Owners . Clear ( ) ;
118+ }
115119 }
116120
117121 public bool Contains ( string key )
118122 {
119123 if ( string . IsNullOrWhiteSpace ( key ) )
124+ {
120125 return false ;
126+ }
121127
122128 if ( ! States . TryGetValue ( Context , out var state ) )
129+ {
123130 return false ;
131+ }
124132
125133 lock ( state . Sync )
134+ {
126135 return state . Owners . Contains ( key ) ;
136+ }
127137 }
128138
129139 public bool ContainsOnly ( string key )
130140 {
131141 if ( string . IsNullOrWhiteSpace ( key ) )
142+ {
132143 return false ;
144+ }
133145
134146 if ( ! States . TryGetValue ( Context , out var state ) )
147+ {
135148 return false ;
149+ }
136150
137151 lock ( state . Sync )
138- return state . Owners . Count == 1 &&
139- state . Owners . Contains ( key ) ;
152+ {
153+ return state . Owners . Count == 1 && state . Owners . Contains ( key ) ;
154+ }
140155 }
141156
142157 public int Count
143158 {
144159 get
145160 {
146161 if ( ! States . TryGetValue ( Context , out var state ) )
162+ {
147163 return 0 ;
164+ }
148165
149166 lock ( state . Sync )
167+ {
150168 return state . Owners . Count ;
169+ }
151170 }
152171 }
153172
154173 public List < string > ToList ( )
155174 {
156175 if ( ! States . TryGetValue ( Context , out var state ) )
176+ {
157177 return new List < string > ( ) ;
178+ }
158179
159180 lock ( state . Sync )
181+ {
160182 return state . Owners . ToList ( ) ;
183+ }
161184 }
162185
163186 public override string ToString ( )
164187 {
165188 if ( ! States . TryGetValue ( Context , out var state ) )
189+ {
166190 return $ "{ Context } []";
191+ }
167192
168193 lock ( state . Sync )
169194 {
170- if ( state . Owners . Count == 0 )
171- return $ "{ Context } []";
172-
173- return $ "{ Context } [{ string . Join ( ", " , state . Owners ) } ]";
195+ return state . Owners . Count == 0 ? $ "{ Context } []" : $ "{ Context } [{ string . Join ( ", " , state . Owners ) } ]";
174196 }
175197 }
176198
@@ -192,14 +214,11 @@ public override int GetHashCode()
192214 return Context . GetHashCode ( ) ;
193215 }
194216
195- public static bool operator == ( LockContext a , LockContext b )
196- => a ? . Context == b ? . Context ;
217+ public static bool operator == ( LockContext a , LockContext b ) => a ? . Context == b ? . Context ;
197218
198- public static bool operator != ( LockContext a , LockContext b )
199- => ! ( a == b ) ;
219+ public static bool operator != ( LockContext a , LockContext b ) => ! ( a == b ) ;
200220
201- public static implicit operator bool ( LockContext context )
202- => context != null && context . Count > 0 ;
221+ public static implicit operator bool ( LockContext context ) => context != null && context . Count > 0 ;
203222 }
204223 }
205224}
0 commit comments