File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
libraries/src/AWS.Lambda.Powertools.Logging/Internal/Helpers Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 1313 * permissions and limitations under the License.
1414 */
1515
16+ using System ;
1617using System . Collections . Generic ;
1718using System . Linq ;
19+ using System . Reflection ;
20+ using System . Text . Json . Serialization ;
1821
1922namespace AWS . Lambda . Powertools . Logging . Internal . Helpers ;
2023
@@ -38,18 +41,31 @@ internal static object ObjectToDictionary(object anonymousObject)
3841 return new Dictionary < string , object > ( ) ;
3942 }
4043
41- if ( anonymousObject . GetType ( ) . Namespace is not null )
44+ var type = anonymousObject . GetType ( ) ;
45+
46+ if ( type . IsEnum )
47+ {
48+ return anonymousObject ;
49+ }
50+
51+ if ( type . Namespace != null && ! type . IsEnum )
4252 {
4353 return anonymousObject ;
4454 }
4555
46- return anonymousObject . GetType ( ) . GetProperties ( )
56+ return type . GetProperties ( )
4757 . Where ( prop => prop . GetValue ( anonymousObject , null ) != null )
4858 . ToDictionary (
4959 prop => prop . Name ,
5060 prop => {
5161 var value = prop . GetValue ( anonymousObject , null ) ;
52- return value != null ? ObjectToDictionary ( value ) : string . Empty ;
62+ if ( value == null )
63+ return string . Empty ;
64+
65+ if ( value . GetType ( ) . IsEnum )
66+ return value ;
67+
68+ return ObjectToDictionary ( value ) ;
5369 }
5470 ) ;
5571 }
You can’t perform that action at this time.
0 commit comments