public DocumentJsonWriter(TextWriter textWriter, DocumentSerializationMeta documentMeta, SerializationConventions conventions, IEntityReflector entityReflector)
            : base(textWriter)
        {
            EnsureArg.IsNotNull(documentMeta, nameof(documentMeta));
            EnsureArg.IsNotNull(conventions, nameof(conventions));
            EnsureArg.IsNotNull(entityReflector, nameof(entityReflector));

            HasWrittenDocumentMeta = false;
            DocumentMeta           = documentMeta;
            Conventions            = conventions;
            ConventionWriter       = new SerializationConventionWriter(this);
            EntityReflector        = entityReflector;
            CloseOutput            = false;
        }
        protected virtual DocumentSerializationMeta CreateFor(Type docType)
        {
            var isAnonymous = CheckIfDocTypeIsAnonymous(docType);
            var metaAttr    = ExtractMetaDataAttribute(docType);
            var type        = metaAttr == null ? docType.Name : metaAttr.DocType ?? docType.Name;

            var meta = new DocumentSerializationMeta(docType, type, isAnonymous);

            if (metaAttr != null)
            {
                meta.DocNamespace = metaAttr.DocNamespace;
                meta.DocVersion   = metaAttr.DocVersion;
            }

            return(meta);
        }
示例#3
0
 public virtual void Apply(DocumentSerializationMeta meta, ISerializationConventionWriter writer)
 {
     WriteIfValueExists(Convention(meta), writer);
 }
        protected virtual void WriteDocumentMetaConvention(ISerializationConvention convention, DocumentSerializationMeta meta)
        {
            if (convention == null)
            {
                return;
            }

            convention.Apply(meta, ConventionWriter);
        }
 protected virtual void WriteDocumentMeta(DocumentSerializationMeta meta)
 {
     WriteDocumentMetaConvention(Conventions.DocType, meta);
     WriteDocumentMetaConvention(Conventions.DocNamespace, meta);
     WriteDocumentMetaConvention(Conventions.DocVersion, meta);
 }