@@ -217,6 +217,67 @@ private bool IsTypeTypeExplicitlyRegisteredLocally(Type type)
217217 return _parent ? . _isTypeExplicitlyRegistered ( type ) ?? false ;
218218 }
219219
220+ internal bool RegistrationExists ( Type type , string name )
221+ {
222+ IPolicySet defaultRegistration = null ;
223+ IPolicySet noNameRegistration = null ;
224+
225+ var hashCode = ( type ? . GetHashCode ( ) ?? 0 ) & 0x7FFFFFFF ;
226+ for ( var container = this ; null != container ; container = container . _parent )
227+ {
228+ if ( null == _registrations ) continue ;
229+
230+ var targetBucket = hashCode % container . _registrations . Buckets . Length ;
231+ for ( var i = container . _registrations . Buckets [ targetBucket ] ; i >= 0 ; i = container . _registrations . Entries [ i ] . Next )
232+ {
233+ if ( container . _registrations . Entries [ i ] . HashCode != hashCode ||
234+ container . _registrations . Entries [ i ] . Key != type )
235+ {
236+ continue ;
237+ }
238+
239+ var registry = container . _registrations . Entries [ i ] . Value ;
240+
241+ if ( null != registry [ name ] ) return true ;
242+ if ( null == defaultRegistration ) defaultRegistration = registry [ string . Empty ] ;
243+ if ( null != name && null == noNameRegistration ) noNameRegistration = registry [ null ] ;
244+ }
245+ }
246+
247+ if ( null != defaultRegistration ) return true ;
248+ if ( null != noNameRegistration ) return true ;
249+
250+ var info = type . GetTypeInfo ( ) ;
251+ if ( ! info . IsGenericType ) return false ;
252+
253+ type = info . GetGenericTypeDefinition ( ) ;
254+ hashCode = ( type ? . GetHashCode ( ) ?? 0 ) & 0x7FFFFFFF ;
255+ for ( var container = this ; null != container ; container = container . _parent )
256+ {
257+ if ( null == _registrations ) continue ;
258+
259+ var targetBucket = hashCode % container . _registrations . Buckets . Length ;
260+ for ( var i = container . _registrations . Buckets [ targetBucket ] ; i >= 0 ; i = container . _registrations . Entries [ i ] . Next )
261+ {
262+ if ( container . _registrations . Entries [ i ] . HashCode != hashCode ||
263+ container . _registrations . Entries [ i ] . Key != type )
264+ {
265+ continue ;
266+ }
267+
268+ var registry = container . _registrations . Entries [ i ] . Value ;
269+
270+ if ( null != registry [ name ] ) return true ;
271+ if ( null == defaultRegistration ) defaultRegistration = registry [ string . Empty ] ;
272+ if ( null != name && null == noNameRegistration ) noNameRegistration = registry [ null ] ;
273+ }
274+ }
275+
276+ if ( null != defaultRegistration ) return true ;
277+ return null != noNameRegistration ;
278+ }
279+
280+
220281 #endregion
221282
222283
0 commit comments