memberValue.ActualMemberType ?? memberValue.MemberType
/// <summary> /// Deserializes the object using the <c>Parse(string, IFormatProvider)</c> method. /// </summary> /// <returns>The deserialized object.</returns> protected virtual object DeserializeUsingObjectParse(ISerializationContext <TSerializationContext> context, MemberValue memberValue) { // Note: don't use GetBestMemberType, it could return string type var parseMethod = GetObjectParseMethod(memberValue.MemberType); if (parseMethod == null) { return(null); } var memberValueAsString = memberValue.Value as string; if (memberValueAsString == null) { return(null); } try { var obj = parseMethod.Invoke(null, new object[] { memberValueAsString, context.Configuration.Culture }); return(obj); } catch (Exception ex) { Log.Warning(ex, $"Failed to deserialize type '{memberValue.GetBestMemberType().GetSafeFullName(false)}' using Parse(string, IFormatProvider)"); return(null); } }
/// <summary> /// Returns whether the member value should be serialized as dictionary. /// </summary> /// <param name="memberValue">The member value.</param> /// <returns><c>true</c> if the member value should be serialized as dictionary, <c>false</c> otherwise.</returns> protected bool ShouldSerializeAsDictionary(MemberValue memberValue) { if (memberValue.MemberGroup == SerializationMemberGroup.Dictionary) { return(true); } return(ShouldSerializeAsDictionary(memberValue.GetBestMemberType())); }
/// <summary> /// Returns whether json.net should handle the member. /// <para /> /// By default it only handles non-class types. /// </summary> /// <param name="memberValue">The member value.</param> /// <returns><c>true</c> if json.net should handle the type, <c>false</c> otherwise.</returns> protected virtual bool ShouldExternalSerializerHandleMember(MemberValue memberValue) { if (memberValue.MemberGroup == SerializationMemberGroup.Collection) { return(false); } return(ShouldExternalSerializerHandleMember(memberValue.GetBestMemberType())); }
/// <summary> /// Returns whether the member value should be serialized as collection. /// </summary> /// <param name="memberValue">The member value.</param> /// <returns><c>true</c> if the member value should be serialized as collection, <c>false</c> otherwise.</returns> protected bool ShouldSerializeAsCollection(MemberValue memberValue) { if (memberValue.MemberGroup == SerializationMemberGroup.Collection) { return(true); } return(ShouldSerializeAsCollection(memberValue.GetBestMemberType())); }
/// <summary> /// Deserializes the object using the <c>Parse(string, IFormatProvider)</c> method. /// </summary> /// <returns>The deserialized object.</returns> protected virtual string SerializeUsingObjectToString(ISerializationContext <TSerializationContext> context, MemberValue memberValue) { var toStringMethod = GetObjectToStringMethod(memberValue.GetBestMemberType()); if (toStringMethod == null) { return(null); } try { var stringValue = (string)toStringMethod.Invoke(memberValue.Value, new object[] { context.Configuration.Culture }); return(stringValue); } catch (Exception ex) { Log.Warning(ex, $"Failed to serialize type '{memberValue.GetBestMemberType().GetSafeFullName(false)}' using ToString(IFormatProvider)"); return(null); } }