Exemple #1
0
        public static JsonConverter GetJsonConverter(object attributeProvider)
        {
            JsonConverterAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute <JsonConverterAttribute>(attributeProvider);

            if (cachedAttribute != null)
            {
                Func <object[], JsonConverter> func = JsonTypeReflector.JsonConverterCreatorCache.Get(cachedAttribute.ConverterType);
                if (func != null)
                {
                    return(func(cachedAttribute.ConverterParameters));
                }
            }
            return(null);
        }
        internal JsonContainerContract(Type underlyingType) : base(underlyingType)
        {
            JsonContainerAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(underlyingType);

            if (cachedAttribute != null)
            {
                if (cachedAttribute.ItemConverterType != null)
                {
                    this.ItemConverter = JsonTypeReflector.CreateJsonConverterInstance(cachedAttribute.ItemConverterType, cachedAttribute.ItemConverterParameters);
                }
                this.ItemIsReference           = cachedAttribute._itemIsReference;
                this.ItemReferenceLoopHandling = cachedAttribute._itemReferenceLoopHandling;
                this.ItemTypeNameHandling      = cachedAttribute._itemTypeNameHandling;
            }
        }
Exemple #3
0
        public static MemberSerialization GetObjectMemberSerialization(
            Type objectType,
            bool ignoreSerializableAttribute)
        {
            JsonObjectAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute <JsonObjectAttribute>((object)objectType);

            if (cachedAttribute != null)
            {
                return(cachedAttribute.MemberSerialization);
            }
            if (JsonTypeReflector.GetDataContractAttribute(objectType) != null)
            {
                return(MemberSerialization.OptIn);
            }
            return(!ignoreSerializableAttribute && JsonTypeReflector.GetCachedAttribute <SerializableAttribute>((object)objectType) != null ? MemberSerialization.Fields : MemberSerialization.OptOut);
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonContainerContract"/> class.
        /// </summary>
        /// <param name="underlyingType">The underlying type for the contract.</param>
        internal JsonContainerContract(Type underlyingType)
            : base(underlyingType)
        {
            JsonContainerAttribute jsonContainerAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(underlyingType);

            if (jsonContainerAttribute != null)
            {
                if (jsonContainerAttribute.ItemConverterType != null)
                {
                    ItemConverter = JsonTypeReflector.CreateJsonConverterInstance(jsonContainerAttribute.ItemConverterType);
                }

                ItemIsReference           = jsonContainerAttribute._itemIsReference;
                ItemReferenceLoopHandling = jsonContainerAttribute._itemReferenceLoopHandling;
                ItemTypeNameHandling      = jsonContainerAttribute._itemTypeNameHandling;
            }
        }