11using Microsoft . Extensions . Logging ;
22using System ;
33using System . Collections . Generic ;
4- using System . Linq ;
54
65namespace SimpleStateMachineLibrary . Helpers
76{
87 internal class Check
98 {
10- //= null
119 public static string Name ( string name , ILogger logger )
1210 {
1311 if ( String . IsNullOrEmpty ( name ) )
1412 {
1513 string message = "Name must be not Empty" ;
1614 var ex = new ArgumentNullException ( message : message , paramName : "Name" ) ;
17- logger . LogError ( ex , message ) ;
15+ logger ? . LogError ( ex , message ) ;
1816 throw ex ;
1917 }
2018
@@ -28,7 +26,7 @@ public static TObject Object<TObject>(TObject objectRequested, ILogger logger)
2826 object [ ] args = { typeof ( TObject ) . Name } ;
2927 string message = "Object of type \" {0}\" must be not null" ;
3028 var ex = new ArgumentNullException ( message : String . Format ( message , args ) , paramName : typeof ( TObject ) . Name ) ;
31- logger . LogError ( ex , message , args ) ;
29+ logger ? . LogError ( ex , message , args ) ;
3230 throw ex ;
3331 }
3432
@@ -55,7 +53,7 @@ public static bool Contains<TObject>(Dictionary<string, TObject> dictionary, str
5553 object [ ] args = { nameObject } ;
5654 string message = "Element with name \" {0}\" is not found" ;
5755 var ex = new KeyNotFoundException ( message : String . Format ( message , args ) ) ;
58- logger . LogError ( ex , message , args ) ;
56+ logger ? . LogError ( ex , message , args ) ;
5957 throw ex ;
6058 }
6159
@@ -74,7 +72,7 @@ public static bool Contains<TObject>(Dictionary<string, TObject> dictionary, TOb
7472 object [ ] args = { objectRequested . Name } ;
7573 string message = "Element with name \" {0}\" is not found" ;
7674 var ex = new KeyNotFoundException ( message : String . Format ( message , args ) ) ;
77- logger . LogError ( ex , message , args ) ;
75+ logger ? . LogError ( ex , message , args ) ;
7876 throw ex ;
7977 }
8078
@@ -92,7 +90,7 @@ public static bool NotContains<TObject>(Dictionary<string, TObject> dictionary,
9290 object [ ] args = { nameObject } ;
9391 string message = "Element of type \" {0}\" already exists" ;
9492 var ex = new KeyNotFoundException ( message : String . Format ( message , args ) ) ;
95- logger . LogError ( ex , message , args ) ;
93+ logger ? . LogError ( ex , message , args ) ;
9694 throw ex ;
9795 }
9896
@@ -111,12 +109,13 @@ public static bool NotContains<TObject>(Dictionary<string, TObject> dictionary,
111109 object [ ] args = { objectRequested . Name } ;
112110 string message = "Element of type \" {0}\" already exists" ;
113111 var ex = new KeyNotFoundException ( message : String . Format ( message , args ) ) ;
114- logger . LogError ( ex , message , args ) ;
112+ logger ? . LogError ( ex , message , args ) ;
115113 throw ex ;
116114 }
117115
118116 return notContains ;
119117 }
118+
120119
121120 public static TObject Remove < TObject > ( Dictionary < string , TObject > dictionary , string nameObject , ILogger logger , out bool result , bool exception = true ) where TObject : NamedObject
122121 {
@@ -134,7 +133,7 @@ public static TObject Remove<TObject>(Dictionary<string, TObject> dictionary, st
134133 object [ ] args = { nameObject } ;
135134 string message = "Element with name \" {0}\" is not deleted because not found" ;
136135 var ex = new KeyNotFoundException ( String . Format ( message , args ) ) ;
137- logger . LogError ( ex , message , args ) ;
136+ logger ? . LogError ( ex , message , args ) ;
138137 throw ex ;
139138 }
140139
@@ -163,7 +162,7 @@ public static TObject Remove<TObject>(Dictionary<string, TObject> dictionary, TO
163162 object [ ] args = { obj . Name } ;
164163 string message = "Element with name \" {0}\" is not deleted because not found" ;
165164 var ex = new KeyNotFoundException ( String . Format ( message , args ) ) ;
166- logger . LogError ( ex , message , args ) ;
165+ logger ? . LogError ( ex , message , args ) ;
167166 throw ex ;
168167 }
169168
0 commit comments