11using System . Text . Json ;
2- using Util . Dates ;
32using Util . Domain . Extending ;
43using Util . Helpers ;
54
6- namespace Util . Domain ;
5+ namespace Util . Domain ;
76
87/// <summary>
98/// 扩展属性字典扩展
@@ -16,16 +15,10 @@ public static class ExtraPropertyDictionaryExtensions {
1615 /// <param name="name">属性名</param>
1716 public static TProperty GetProperty < TProperty > ( this ExtraPropertyDictionary source , string name ) {
1817 source . CheckNull ( nameof ( source ) ) ;
19- if ( source . ContainsKey ( name ) == false )
18+ if ( source . TryGetValue ( name , out var value ) == false )
2019 return default ;
21- var value = source [ name ] ;
22- if ( value is JsonElement element ) {
23- var date = Util . Helpers . Convert . ToDateTimeOrNull ( element . GetRawText ( ) . Trim ( '"' ) ) ;
24- if ( date != null )
25- value = date ;
26- }
27- if ( value is DateTime dateValue && TimeOptions . IsUseUtc )
28- value = Time . UtcToLocalTime ( dateValue ) ;
20+ if ( value is JsonElement element )
21+ return Util . Helpers . Json . ToObject < TProperty > ( Util . Helpers . Json . ToJson ( element ) ) ;
2922 return Util . Helpers . Convert . To < TProperty > ( value ) ;
3023 }
3124
@@ -40,7 +33,7 @@ public static ExtraPropertyDictionary SetProperty( this ExtraPropertyDictionary
4033 source . RemoveProperty ( name ) ;
4134 if ( value == null )
4235 return source ;
43- source [ name ] = GetPropertyValue ( source , value ) ;
36+ source [ name ] = GetPropertyValue ( source , value ) ;
4437 return source ;
4538 }
4639
@@ -50,7 +43,7 @@ public static ExtraPropertyDictionary SetProperty( this ExtraPropertyDictionary
5043 private static object GetPropertyValue ( ExtraPropertyDictionary source , object value ) {
5144 if ( value is string && source . IsTrimString )
5245 return value . SafeString ( ) ;
53- if ( value is DateTime dateValue && TimeOptions . IsUseUtc )
46+ if ( value is DateTime dateValue )
5447 return Time . Normalize ( dateValue ) ;
5548 return value ;
5649 }
@@ -62,7 +55,7 @@ private static object GetPropertyValue( ExtraPropertyDictionary source, object v
6255 /// <param name="name">属性名</param>
6356 public static ExtraPropertyDictionary RemoveProperty ( this ExtraPropertyDictionary source , string name ) {
6457 source . CheckNull ( nameof ( source ) ) ;
65- if ( source . ContainsKey ( name ) )
58+ if ( source . ContainsKey ( name ) )
6659 source . Remove ( name ) ;
6760 return source ;
6861 }
0 commit comments