Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EncoderConfiguration"/> class.
        /// </summary> 
        /// <param name="configuration">
        /// The encoder configuration to take over.
        /// </param>
        internal EncoderConfiguration(EncoderConfiguration configuration)
        {
            if (configuration != null)
            {
                this.binder = configuration.binder;
                this.typeWriter = configuration.typeWriter;

                this.StrictExplicitTypeCodes = configuration.StrictExplicitTypeCodes;
                this.DateTimeBehavior = configuration.DateTimeBehavior;
            }
        }
Example #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EncoderConfiguration" /> class.
        /// </summary>
        /// <param name="configuration">
        ///     The encoder configuration to take over.
        /// </param>
        internal EncoderConfiguration(EncoderConfiguration configuration)
        {
            if (configuration != null)
            {
                this.binder     = configuration.binder;
                this.typeWriter = configuration.typeWriter;

                this.StrictExplicitTypeCodes = configuration.StrictExplicitTypeCodes;
                this.DateTimeBehavior        = configuration.DateTimeBehavior;
            }
        }
Example #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EncoderConfiguration" /> class.
        /// </summary>
        /// <param name="configuration">
        ///     The encoder configuration to take over.
        /// </param>
        /// <param name="defaultConfiguration">
        ///     The encoder default configuration.
        /// </param>
        private EncoderConfiguration(EncoderConfiguration configuration, EncoderConfiguration defaultConfiguration)
            : this(configuration)
        {
            if (defaultConfiguration != null)
            {
                if (this.binder == null)
                {
                    this.binder = defaultConfiguration.binder;
                }

                if (this.typeWriter == null)
                {
                    this.typeWriter = defaultConfiguration.typeWriter;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Write a type value to the binary writer.
        /// </summary>
        /// <param name="binaryWriter">
        /// The binary writer.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="configuration">
        /// The encoder configuration.
        /// </param>
        /// <param name="writeTag">
        /// If <c>true</c> the encoder writes the leading type tag, otherwise <c>false</c>.
        /// </param>
        internal static void WriteType(BinaryWriter binaryWriter, Type value, EncoderConfiguration configuration, bool writeTag)
        {
            if (configuration.StrictExplicitTypeCodes)
            {
                throw new SerializationException(string.Format(CultureInfo.InvariantCulture, @"Missing type code for type {0}", value));
            }

            if (writeTag)
            {
                WriteTag(binaryWriter, Tags.Type);
            }

            configuration.TypeWriter(binaryWriter, value, configuration);
        }
Example #5
0
        /// <summary>
        /// Write a date time value to the binary writer.
        /// </summary>
        /// <param name="binaryWriter">
        /// The binary writer.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="configuration">
        /// The encoder configuration.
        /// </param>
        /// <param name="writeTag">
        /// If <c>true</c> the encoder writes the leading type tag, otherwise <c>false</c>.
        /// </param>
        public static void WriteDateTime(BinaryWriter binaryWriter, DateTime value, EncoderConfiguration configuration, bool writeTag)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            if (writeTag)
            {
                if (value.Ticks == 0)
                {
                    WriteTag(binaryWriter, Tags.DateTime0);
                    return;
                }

                WriteTag(binaryWriter, Tags.DateTime);
            }

            if (configuration.DateTimeBehavior == DateTimeBehavior.Utc)
            {
                WriteByte(binaryWriter, (byte)value.Kind, false);
                WriteLongVariant(binaryWriter, value.Kind == DateTimeKind.Local ? value.ToUniversalTime().Ticks : value.Ticks);
            }
            else {
                var kindAndFlag = (byte)value.Kind;
                if (value.Kind == DateTimeKind.Local)
                {
                    kindAndFlag |= LocalTimeTicks;
                }

                WriteByte(binaryWriter, kindAndFlag, false);
                WriteLongVariant(binaryWriter, value.Ticks);
            }
        }
Example #6
0
 /// <summary>
 /// Write a type value to the binary writer.
 /// </summary>
 /// <param name="binaryWriter">
 /// The binary writer.
 /// </param>
 /// <param name="type">
 /// The type.
 /// </param>
 /// <param name="configuration">
 /// The encoder configuration.
 /// </param>
 private static void WriteType(BinaryWriter binaryWriter, Type type, EncoderConfiguration configuration)
 {
     WriteType(binaryWriter, type, configuration.Binder);
 }
Example #7
0
 /// <summary>
 /// Creates a new instance of the <see cref="EncoderConfiguration"/> class.
 /// </summary> 
 /// <param name="configuration">
 /// The encoder configuration to take over.
 /// </param>
 internal static EncoderConfiguration CreateFrom(EncoderConfiguration configuration)
 {
     return configuration != null ? new EncoderConfiguration(configuration, Encoder.Configuration) : new EncoderConfiguration(Encoder.Configuration);
 }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EncoderConfiguration"/> class.
        /// </summary> 
        /// <param name="configuration">
        /// The encoder configuration to take over.
        /// </param>
        /// <param name="defaultConfiguration">
        /// The encoder default configuration.
        /// </param>
        private EncoderConfiguration(EncoderConfiguration configuration, EncoderConfiguration defaultConfiguration)
            : this(configuration)
        {
            if (defaultConfiguration != null)
            {
                if (this.binder == null)
                {
                    this.binder = defaultConfiguration.binder;
                }

                if (this.typeWriter == null)
                {
                    this.typeWriter = defaultConfiguration.typeWriter;
                }
            }
        }
Example #9
0
 /// <summary>
 ///     Creates a new instance of the <see cref="EncoderConfiguration" /> class.
 /// </summary>
 /// <param name="configuration">
 ///     The encoder configuration to take over.
 /// </param>
 internal static EncoderConfiguration CreateFrom(EncoderConfiguration configuration)
 {
     return(configuration != null
         ? new EncoderConfiguration(configuration, Encoder.Configuration)
         : new EncoderConfiguration(Encoder.Configuration));
 }