@@ -16,22 +16,22 @@ public class ProjectUnit<TSource, TResult> : IProjectUnit<TSource, TResult>
1616
1717 public IProjectUnit < TSource , TResult > AddGenerator ( IGenerator < TSource , TResult > Generator , bool Condition = true )
1818 {
19- if ( Condition ) _Generator . Add ( Generator . ToString ( ) , Generator ) ; return this ;
19+ if ( Condition && Generator != null ) _Generator . Add ( Generator . ToString ( ) , Generator ) ; return this ;
2020 }
2121
2222 public IProjectUnit < TSource , TResult > AddGeneratorCollection ( IEnumerable < IGenerator < TSource , TResult > > Collection , bool Condition = true )
2323 {
24- if ( Condition ) Collection . Each ( x => _Generator . Add ( x . ToString ( ) , x ) ) ; return this ;
24+ if ( Condition && Collection != null ) Collection . Each ( x => { if ( x != null ) _Generator . Add ( x . ToString ( ) , x ) ; } ) ; return this ;
2525 }
2626
2727 public IProjectUnit < TSource , TResult > AddPostProcessor ( IPostProcessor < TResult > PostProcessor , bool Condition = true )
2828 {
29- if ( Condition ) _PostProcessor . Add ( PostProcessor . ToString ( ) , PostProcessor ) ; return this ;
29+ if ( Condition && PostProcessor != null ) _PostProcessor . Add ( PostProcessor . ToString ( ) , PostProcessor ) ; return this ;
3030 }
3131
3232 public IProjectUnit < TSource , TResult > AddPostProcessorCollection ( IEnumerable < IPostProcessor < TResult > > Collection , bool Condition = true )
3333 {
34- if ( Condition ) Collection . Each ( x => _PostProcessor . Add ( x . ToString ( ) , x ) ) ; return this ;
34+ if ( Condition && Collection != null ) Collection . Each ( x => { if ( x != null ) _PostProcessor . Add ( x . ToString ( ) , x ) ; } ) ; return this ;
3535 }
3636
3737 public IEnumerable < TResult > RunGenerator ( TSource Model , Action < IGenerator < TSource , TResult > , Exception > OnError = null )
@@ -46,7 +46,7 @@ public IEnumerable<TResult> RunPostProcessor(IEnumerable<TResult> ResultCollecti
4646
4747 public IEnumerable < TResult > Run ( TSource Model , Action < IGenerator < TSource , TResult > , Exception > OnGeneratorError = null , Action < IPostProcessor < TResult > , Exception > OnPostProcessorError = null )
4848 {
49- return RunPostProcessor ( RunGenerator ( Model , OnGeneratorError ) , OnPostProcessorError ) ;
49+ return Run ( Model , _Generator . Values , _PostProcessor . Values , OnGeneratorError , OnPostProcessorError ) ;
5050 }
5151
5252 public static IProjectUnit < TSource , TResult > Create ( )
@@ -68,7 +68,7 @@ public static IEnumerable<TResult> RunGenerator(TSource Model, IEnumerable<IGene
6868 }
6969 catch ( Exception Error )
7070 {
71- OnError ? . Invoke ( Generator , Error ) ;
71+ if ( OnError != null ) OnError . Invoke ( Generator , Error ) ;
7272 }
7373 }
7474
@@ -77,7 +77,6 @@ public static IEnumerable<TResult> RunGenerator(TSource Model, IEnumerable<IGene
7777
7878 public static IEnumerable < TResult > RunPostProcessor ( IEnumerable < TResult > ResultCollection , IEnumerable < IPostProcessor < TResult > > PostProcessorCollection , Action < IPostProcessor < TResult > , Exception > OnError = null )
7979 {
80- var ResultList = new List < TResult > ( ) ;
8180 var _PostProcessorCollection = PostProcessorCollection . OrderByDescending ( x => x . Priority ) ;
8281 var Current = ResultCollection ;
8382
@@ -89,7 +88,7 @@ public static IEnumerable<TResult> RunPostProcessor(IEnumerable<TResult> ResultC
8988 }
9089 catch ( Exception Error )
9190 {
92- OnError ? . Invoke ( PostProcessor , Error ) ;
91+ if ( OnError != null ) OnError . Invoke ( PostProcessor , Error ) ;
9392 }
9493 }
9594
0 commit comments