/// <inheritdoc/>
 public IIonWriter Create(IonSerializationOptions options, Stream stream)
 {
     return(options.Format switch
     {
         BINARY => IonBinaryWriterBuilder.Build(stream),
         TEXT => IonTextWriterBuilder.Build(new StreamWriter(stream)),
         PRETTY_TEXT => IonTextWriterBuilder.Build(
             new StreamWriter(stream),
             new IonTextOptions {
             PrettyPrint = true
         }),
         _ => throw new InvalidOperationException($"Format {options.Format} not supported"),
     });
        /// <inheritdoc/>
        public void Apply(IonSerializationOptions options, IIonWriter writer, Type type)
        {
            IonAnnotateTypeAttribute annotateType = this.ShouldAnnotate(type, type);

            if (annotateType == null && options.IncludeTypeInformation)
            {
                // the serializer insists on type information being included
                annotateType = new IonAnnotateTypeAttribute();
            }

            if (annotateType != null)
            {
                writer.AddTypeAnnotation(options.AnnotationConvention.Apply(options, annotateType, type));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="IonGuidSerializer"/> class.
 /// </summary>
 ///
 /// <param name="options">Serialization options for customizing serializer behavior.</param>
 public IonGuidSerializer(IonSerializationOptions options)
 {
     this.options = options;
 }
Beispiel #4
0
 /// <inheritdoc/>
 IIonSerializer IIonSerializerFactory.Create(IonSerializationOptions options, Dictionary <string, object> customContext)
 {
     return(this.Create(options, customContext));
 }
Beispiel #5
0
 /// <summary>
 /// Create custom IonSerializer with customContext option.
 /// </summary>
 ///
 /// <param name="options">Serialization options for customizing serializer behavior.</param>
 /// <param name="customContext">
 /// A mapping between strings and arbitrary data that can be used to
 /// create a serializer with custom serialization/deserialization logic.
 /// </param>
 ///
 /// <returns>The customized IonSerializer.</returns>
 public abstract IonSerializer <T> Create(IonSerializationOptions options, Dictionary <string, object> customContext);
 /// <inheritdoc/>
 public object Create(IonSerializationOptions options, IIonReader reader, Type targetType)
 {
     return(Activator.CreateInstance(targetType));
 }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IonObjectSerializer"/> class.
 /// </summary>
 ///
 /// <param name="ionSerializer">Serializer to be used for serializing/deserializing non-primitive objects.</param>
 /// <param name="options">Serialization options for customizing serializer behavior.</param>
 /// <param name="targetType">The type of data being serialized/deserialized.</param>
 public IonObjectSerializer(IonSerializer ionSerializer, IonSerializationOptions options, Type targetType)
 {
     this.ionSerializer = ionSerializer;
     this.options       = options;
     this.targetType    = targetType;
 }
 /// <inheritdoc/>
 public string Apply(IonSerializationOptions options, IonAnnotateTypeAttribute annotateType, Type type)
 {
     annotateType.Prefix ??= options.TypeAnnotationPrefix.Apply(type);
     annotateType.Name ??= options.TypeAnnotationName.Apply(type);
     return(annotateType.Prefix + "." + annotateType.Name);
 }