예제 #1
0
        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);
        }
예제 #2
0
 /// <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));
 }
예제 #3
0
        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);
        }