88using Platform . Collections . Lists ;
99using Platform . Reflection ;
1010using Platform . Singletons ;
11+ using System . Runtime . CompilerServices ;
1112
1213#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
1314
@@ -25,38 +26,50 @@ public class Scope : DisposableBase
2526 private readonly HashSet < object > _blocked = new HashSet < object > ( ) ;
2627 private readonly Dictionary < Type , object > _resolutions = new Dictionary < Type , object > ( ) ;
2728
29+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
2830 public Scope ( bool autoInclude , bool autoExplore )
2931 {
3032 _autoInclude = autoInclude ;
3133 _autoExplore = autoExplore ;
3234 }
3335
36+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
3437 public Scope ( bool autoInclude ) : this ( autoInclude , false ) { }
3538
39+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
3640 public Scope ( ) { }
3741
3842 #region Exclude
3943
44+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4045 public void ExcludeAssemblyOf < T > ( ) => ExcludeAssemblyOfType ( typeof ( T ) ) ;
4146
47+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4248 public void ExcludeAssemblyOfType ( Type type ) => ExcludeAssembly ( type . GetAssembly ( ) ) ;
4349
50+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4451 public void ExcludeAssembly ( Assembly assembly ) => assembly . GetCachedLoadableTypes ( ) . ForEach ( Exclude ) ;
4552
53+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4654 public void Exclude < T > ( ) => Exclude ( typeof ( T ) ) ;
4755
56+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4857 public void Exclude ( object @object ) => _excludes . Add ( @object ) ;
4958
5059 #endregion
5160
5261 #region Include
5362
63+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5464 public void IncludeAssemblyOf < T > ( ) => IncludeAssemblyOfType ( typeof ( T ) ) ;
5565
66+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5667 public void IncludeAssemblyOfType ( Type type ) => IncludeAssembly ( type . GetAssembly ( ) ) ;
5768
69+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5870 public void IncludeAssembly ( Assembly assembly ) => assembly . GetExportedTypes ( ) . ForEach ( Include ) ;
5971
72+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
6073 public void Include < T > ( )
6174 {
6275 var types = Types < T > . Array ;
@@ -70,6 +83,7 @@ public void Include<T>()
7083 }
7184 }
7285
86+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
7387 public void Include ( object @object )
7488 {
7589 if ( @object == null )
@@ -96,6 +110,7 @@ public void Include(object @object)
96110 /// TODO: Think of interface chaining IDoubletLinks[T] (default) -> IDoubletLinks[T] (checker) -> IDoubletLinks[T] (synchronizer) (may be UseChain[IDoubletLinks[T], Types[DefaultLinks, DefaultLinksDependencyChecker, DefaultSynchronizedLinks]]
97111 /// TODO: Add support for factories
98112 /// </remarks>
113+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
99114 public T Use < T > ( )
100115 {
101116 if ( _excludes . Contains ( typeof ( T ) ) )
@@ -118,16 +133,20 @@ public T Use<T>()
118133 return resolved ;
119134 }
120135
136+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
121137 public T UseSingleton < T > ( IFactory < T > factory ) => UseAndReturn ( Singleton . Get ( factory ) ) ;
122138
139+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
123140 public T UseSingleton < T > ( Func < T > creator ) => UseAndReturn ( Singleton . Get ( creator ) ) ;
124141
142+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
125143 public T UseAndReturn < T > ( T @object )
126144 {
127145 Use ( @object ) ;
128146 return @object ;
129147 }
130148
149+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
131150 public void Use ( object @object )
132151 {
133152 Include ( @object ) ;
@@ -138,6 +157,7 @@ public void Use(object @object)
138157
139158 #region Resolve
140159
160+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
141161 public bool TryResolve < T > ( out T resolved )
142162 {
143163 resolved = default ;
@@ -149,6 +169,7 @@ public bool TryResolve<T>(out T resolved)
149169 return result ;
150170 }
151171
172+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
152173 public bool TryResolve ( Type requiredType , out object resolved )
153174 {
154175 resolved = null ;
@@ -223,8 +244,10 @@ public bool TryResolve(Type requiredType, out object resolved)
223244 }
224245 }
225246
247+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
226248 protected virtual void SortConstructors ( List < ConstructorInfo > resultConstructors ) => resultConstructors . Sort ( ( x , y ) => - x . GetParameters ( ) . Length . CompareTo ( y . GetParameters ( ) . Length ) ) ;
227249
250+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
228251 protected virtual bool TryResolveInstance ( List < ConstructorInfo > constructors , out object resolved )
229252 {
230253 for ( var i = 0 ; i < constructors . Count ; i ++ )
@@ -247,6 +270,7 @@ protected virtual bool TryResolveInstance(List<ConstructorInfo> constructors, ou
247270 return false ;
248271 }
249272
273+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
250274 private ConstructorInfo [ ] GetValidConstructors ( Type type )
251275 {
252276 var constructors = type . GetConstructors ( ) ;
@@ -268,6 +292,7 @@ private ConstructorInfo[] GetValidConstructors(Type type)
268292 return constructors ;
269293 }
270294
295+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
271296 private bool TryResolveConstructorArguments ( ConstructorInfo constructor , out object [ ] arguments )
272297 {
273298 var parameters = constructor . GetParameters ( ) ;
@@ -286,6 +311,7 @@ private bool TryResolveConstructorArguments(ConstructorInfo constructor, out obj
286311
287312 #endregion
288313
314+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
289315 protected override void Dispose ( bool manual , bool wasDisposed )
290316 {
291317 if ( ! wasDisposed )
0 commit comments