@@ -1045,7 +1045,7 @@ public class GxUserType : IGxXMLSerializable, ICloneable, IGxJSONAble, IGxJSONSe
10451045 {
10461046 static readonly IGXLogger log = GXLoggerFactory . GetLogger < GxUserType > ( ) ;
10471047 protected GXProperties dirties = new GXProperties ( ) ;
1048-
1048+ private const string PROPERTY_PREFIX = "gxtpr_" ;
10491049 static object setupChannelObject = null ;
10501050 static bool setupChannelInitialized ;
10511051 [ XmlIgnore ]
@@ -1602,27 +1602,29 @@ public Object GetJSONObject()
16021602 ToJSON ( ) ;
16031603 return JsonObj ;
16041604 }
1605-
16061605 private ICollection getFromJSONObjectOrderIterator ( ICollection it )
16071606 {
1608- List < string > v = new List < string > ( ) ;
1607+ if ( GxUploadAttrs . IsEmpty && ! typeof ( GxSilentTrnSdt ) . IsAssignableFrom ( this . GetType ( ) ) )
1608+ {
1609+ return it ;
1610+ }
1611+ List < string > _JsonObjectOrderIterator = new List < string > ( ) ;
1612+
16091613 List < string > vAtEnd = new List < string > ( ) ;
16101614 foreach ( string name in it )
16111615 {
1612- string map = JsonMap ( name ) ;
1613- PropertyInfo objProperty = GetTypeProperty ( "gxtpr_" + ( ! string . IsNullOrEmpty ( map ) ? map : name ) . ToLower ( ) ) ;
1614- if ( name . EndsWith ( "_N" ) || objProperty != null && IsGxUploadAttribute ( objProperty ) )
1616+ if ( name . EndsWith ( "_N" ) || IsGxUploadAttribute ( name ) )
16151617 {
16161618 vAtEnd . Add ( name ) ;
16171619 }
16181620 else
16191621 {
1620- v . Add ( name ) ; //keep the order of attributes that do not end with _N.
1622+ _JsonObjectOrderIterator . Add ( name ) ; //keep the order of attributes that do not end with _N.
16211623 }
16221624 }
16231625 if ( vAtEnd . Count > 0 )
1624- v . AddRange ( vAtEnd ) ;
1625- return v ;
1626+ _JsonObjectOrderIterator . AddRange ( vAtEnd ) ;
1627+ return _JsonObjectOrderIterator ;
16261628 }
16271629
16281630 public void FromJSONObject ( dynamic obj )
@@ -1635,9 +1637,7 @@ public void FromJSONObject(dynamic obj)
16351637 foreach ( string name in jsonIterator )
16361638 {
16371639 object currObj = jobj [ name ] ;
1638- string map = JsonMap ( name ) ;
1639- PropertyInfo objProperty = GetTypeProperty ( "gxtpr_" + ( map != null ? map : name ) . ToLower ( ) ) ;
1640-
1640+ PropertyInfo objProperty = GetTypeProperty ( JsonNameToInternalName ( name ) ) ;
16411641 if ( objProperty != null )
16421642 {
16431643 if ( ! JSONHelper . IsJsonNull ( currObj ) )
@@ -1897,32 +1897,64 @@ private bool TryConvertValueToProperty(object Value, PropertyInfo property, out
18971897 return success ;
18981898 }
18991899
1900- [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "GxFxCopRules" , "CR1000:EnforceThreadSafeType" ) ]
1901- private Dictionary < string , bool > gxuploadAttrs = new Dictionary< string , bool > ( ) ;
1902- private bool IsGxUploadAttribute ( PropertyInfo property )
1900+ private static ConcurrentDictionary < string , byte > _gxuploadAttrs ;
1901+ private bool IsGxUploadAttribute ( string jsonPropertyName )
1902+ {
1903+ return GxUploadAttrs . ContainsKey ( JsonNameToInternalName ( jsonPropertyName ) ) ;
1904+ }
1905+ private bool IsGxUploadAttribute ( PropertyInfo propertyInfo )
1906+ {
1907+ return GxUploadAttrs . ContainsKey ( propertyInfo . Name ) ;
1908+ }
1909+ private string JsonNameToInternalName ( string jsonPropertyName )
19031910 {
1904- string key = property . Name ;
1905- if ( ! gxuploadAttrs . ContainsKey ( key ) )
1911+ string map = JsonMap ( jsonPropertyName ) ;
1912+ if ( ! string . IsNullOrEmpty ( map ) )
1913+ return PROPERTY_PREFIX + map . ToLower ( ) ;
1914+ else
1915+ return PROPERTY_PREFIX + jsonPropertyName . ToLower ( ) ;
1916+ }
1917+ private ConcurrentDictionary < string , byte > GxUploadAttrs
1918+ {
1919+ get
19061920 {
1907- bool hasAtt = property . IsDefined ( typeof ( GxUpload ) , false ) ;
1908- gxuploadAttrs . Add ( key , hasAtt ) ;
1921+ if ( _gxuploadAttrs == null )
1922+ {
1923+ _gxuploadAttrs = new ConcurrentDictionary < string , byte > ( ) ;
1924+ foreach ( PropertyInfo property in TypeProperties . Values )
1925+ {
1926+ bool hasAtt = property . IsDefined ( typeof ( GxUpload ) , false ) ;
1927+ if ( hasAtt )
1928+ {
1929+ _gxuploadAttrs . TryAdd ( property . Name . ToLower ( ) , 1 ) ;
1930+ }
1931+ }
1932+ }
1933+ return _gxuploadAttrs ;
19091934 }
1910- return gxuploadAttrs [ key ] ;
19111935 }
1912-
1913- private Hashtable props ;
1936+ private static ConcurrentDictionary < string , PropertyInfo > _typeProps ;
19141937
19151938 private PropertyInfo GetTypeProperty ( string propName )
19161939 {
1917- if ( props == null )
1918- {
1919- props = new Hashtable ( ) ;
1920- foreach ( PropertyInfo prop in this . GetType ( ) . GetProperties ( ) )
1940+ return TypeProperties [ propName ] ;
1941+ }
1942+ private ConcurrentDictionary < string , PropertyInfo > TypeProperties
1943+ {
1944+ get {
1945+ if ( _typeProps == null )
19211946 {
1922- props . Add ( prop . Name . ToLower ( ) , prop ) ;
1947+ _typeProps = new ConcurrentDictionary < string , PropertyInfo > ( ) ;
1948+ foreach ( PropertyInfo prop in this . GetType ( ) . GetProperties ( ) )
1949+ {
1950+ if ( prop . Name . StartsWith ( PROPERTY_PREFIX , StringComparison . OrdinalIgnoreCase ) )
1951+ {
1952+ _typeProps . TryAdd ( prop . Name . ToLower ( ) , prop ) ;
1953+ }
1954+ }
19231955 }
1956+ return _typeProps ;
19241957 }
1925- return ( PropertyInfo ) props [ propName ] ;
19261958 }
19271959
19281960 private Hashtable methods ;
0 commit comments