public static MemberSerialization GetObjectMemberSerialization(Type objectType, bool ignoreSerializableAttribute) { JsonObjectAttribute?objectAttribute = GetCachedAttribute <JsonObjectAttribute>(objectType); if (objectAttribute != null) { return(objectAttribute.MemberSerialization); } #if HAVE_DATA_CONTRACTS DataContractAttribute?dataContractAttribute = GetDataContractAttribute(objectType); if (dataContractAttribute != null) { return(MemberSerialization.OptIn); } #endif #if HAVE_BINARY_SERIALIZATION if (!ignoreSerializableAttribute && IsSerializable(objectType)) { return(MemberSerialization.Fields); } #endif // the default return(MemberSerialization.OptOut); }
/// <summary> /// Creates a namespace resolution for a <see cref="DataContractAttribute" />-annotated /// type. /// </summary> protected virtual IdentifierResolution?CreateNamespaceResolution(Type type, DataContractAttribute?attribute = null) { return(string.IsNullOrEmpty(attribute?.Namespace) ? string.IsNullOrEmpty(type.Namespace) ? null : new IdentifierResolution(type.Namespace) : new IdentifierResolution(attribute !.Namespace, true)); }
public static DataContractAttribute?GetDataContractAttribute(Type type) { // DataContractAttribute does not have inheritance Type currentType = type; while (currentType != null) { DataContractAttribute?result = CachedAttributeGetter <DataContractAttribute> .GetAttribute(currentType); if (result != null) { return(result); } currentType = currentType.BaseType(); } return(null); }