Exemple #1
0
        public ObjectSerializer(SerializationContext context, Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.context    = context;
            this.objectType = type;
            this.objectTypeNameWithoutVersion = GetVersionInvariantObjectTypeName(this.objectType);
            this.SuppressTypeInformation      = (context.Options & SerializationOptions.SuppressTypeInformation) ==
                                                SerializationOptions.SuppressTypeInformation;

            if (this.objectType.BaseType != null && this.objectType.BaseType != typeof(object))
            {
                var baseSerializer = context.GetSerializerForType(this.objectType.BaseType);
                if (baseSerializer is ObjectSerializer == false)
                {
                    throw JsonSerializationException.TypeRequiresCustomSerializer(this.objectType, this.GetType());
                }
                this.baseTypeSerializer = (ObjectSerializer)baseSerializer;
            }

            this.objectTypeDescription = TypeDescription.Get(type);
        }