@@ -3108,57 +3108,6 @@ internal static void WritePropertiesFor(TypeBuilder typeBuilder, Type type, ILGe
31083108
31093109 il . MarkLabel ( skipDefaultValueTrueAndHasValueLabel ) ;
31103110 }
3111-
3112- #region
3113-
3114- //if (_skipDefaultValue) {
3115-
3116- // if (isNullable) {
3117- // var hasValueMethod = originPropType.GetMethod("get_HasValue");
3118- // il.Emit(OpCodes.Ldloca, nullablePropValue);
3119- // il.Emit(OpCodes.Call, hasValueMethod);
3120- // il.Emit(OpCodes.Brfalse, propNullLabel);
3121- // }
3122-
3123- // if (isStruct)
3124- // il.Emit(OpCodes.Ldloca, propValue);
3125- // else
3126- // il.Emit(OpCodes.Ldloc, propValue);
3127- // if (isValueType && isPrimitive) {
3128- // LoadDefaultValueByType(il, propType);
3129- // } else {
3130- // if (!isValueType)
3131- // il.Emit(OpCodes.Ldnull);
3132- // }
3133-
3134- // if (equalityMethod != null) {
3135- // il.Emit(OpCodes.Call, equalityMethod);
3136- // il.Emit(OpCodes.Brtrue, propNullLabel);
3137- // } else {
3138- // if (isStruct) {
3139-
3140- // var tempValue = il.DeclareLocal(propType);
3141-
3142- // il.Emit(OpCodes.Ldloca, tempValue);
3143- // il.Emit(OpCodes.Initobj, propType);
3144- // il.Emit(OpCodes.Ldloc, tempValue);
3145- // il.Emit(OpCodes.Box, propType);
3146- // il.Emit(OpCodes.Constrained, propType);
3147-
3148- // il.Emit(OpCodes.Callvirt, _objectEquals);
3149-
3150- // il.Emit(OpCodes.Brtrue, propNullLabel);
3151-
3152- // } else
3153- // il.Emit(OpCodes.Beq, propNullLabel);
3154- // }
3155- //}
3156-
3157- #endregion
3158-
3159- //if (_skipDefaultValue) {
3160- // il.MarkLabel(propNullLabel);
3161- //}
31623111 }
31633112 counter ++ ;
31643113 }
@@ -3318,6 +3267,11 @@ internal static NetJSONSerializer<T> GetSerializer<T>() {
33183267 /// <param name="value"></param>
33193268 /// <returns></returns>
33203269 public static string Serialize ( Type type , object value ) {
3270+ if ( value == null )
3271+ {
3272+ return null ;
3273+ }
3274+
33213275 return _serializeWithTypes . GetOrAdd ( type , _ => {
33223276 lock ( GetDictLockObject ( "SerializeType" , type . Name ) ) {
33233277 var name = String . Concat ( SerializeStr , type . FullName ) ;
@@ -3354,6 +3308,11 @@ public static string Serialize(Type type, object value) {
33543308 /// <returns></returns>
33553309 public static string Serialize ( Type type , object value , NetJSONSettings settings )
33563310 {
3311+ if ( value == null )
3312+ {
3313+ return null ;
3314+ }
3315+
33573316 return _serializeWithTypesSettings . GetOrAdd ( type , _ => {
33583317 lock ( GetDictLockObject ( "SerializeTypeSetting" , type . Name ) )
33593318 {
@@ -3388,6 +3347,11 @@ public static string Serialize(Type type, object value, NetJSONSettings settings
33883347 /// <param name="value"></param>
33893348 /// <returns></returns>
33903349 public static string Serialize ( object value ) {
3350+ if ( value == null )
3351+ {
3352+ return null ;
3353+ }
3354+
33913355 return Serialize ( value . GetType ( ) , value ) ;
33923356 }
33933357
@@ -3398,6 +3362,11 @@ public static string Serialize(object value) {
33983362 /// <param name="value"></param>
33993363 /// <returns></returns>
34003364 public static object Deserialize ( Type type , string value ) {
3365+ if ( value == null )
3366+ {
3367+ return null ;
3368+ }
3369+
34013370 return _deserializeWithTypes . GetOrAdd ( type . FullName , _ => {
34023371 lock ( GetDictLockObject ( "DeserializeType" , type . Name ) ) {
34033372 var name = String . Concat ( DeserializeStr , type . FullName ) ;
@@ -3436,6 +3405,11 @@ public static object Deserialize(Type type, string value) {
34363405 /// <returns></returns>
34373406 public static object Deserialize ( Type type , string value , NetJSONSettings settings )
34383407 {
3408+ if ( value == null )
3409+ {
3410+ return null ;
3411+ }
3412+
34393413 return _deserializeWithTypesSettings . GetOrAdd ( type . FullName , _ => {
34403414 lock ( GetDictLockObject ( "DeserializeTypeSettings" , type . Name ) )
34413415 {
@@ -3620,6 +3594,11 @@ public static void Serialize<T>(T value, TextWriter writer, NetJSONSettings sett
36203594 /// <returns>String</returns>
36213595 public static string SerializeObject ( object value , NetJSONSettings settings )
36223596 {
3597+ if ( value == null )
3598+ {
3599+ return null ;
3600+ }
3601+
36233602 return Serialize ( value . GetType ( ) , value , settings ) ;
36243603 }
36253604
@@ -5167,7 +5146,7 @@ private static MethodInfo GenerateGetClassOrDictFor(TypeBuilder typeBuilder, Typ
51675146
51685147
51695148 //if (count == 0 && current == 'n') {
5170- // index += 3 ;
5149+ // index += 4 ;
51715150 // return null;
51725151 //}
51735152 il . Emit ( OpCodes . Ldc_I4_0 ) ;
@@ -5178,7 +5157,7 @@ private static MethodInfo GenerateGetClassOrDictFor(TypeBuilder typeBuilder, Typ
51785157 il . Emit ( OpCodes . Ldloc , current ) ;
51795158 il . Emit ( OpCodes . Bne_Un , isNullObjectLabel ) ;
51805159
5181- IncrementIndexRef ( il , count : 3 ) ;
5160+ IncrementIndexRef ( il , count : 4 ) ;
51825161
51835162 if ( isTypeValueType ) {
51845163 var nullLocal = il . DeclareLocal ( type ) ;
0 commit comments