Ejemplo n.º 1
0
 /// <summary>
 /// A generic method to serialize primitive Avro types.
 /// </summary>
 /// <typeparam name="S">Type of the C# type to be serialized</typeparam>
 /// <param name="value">The value to be serialized</param>
 /// <param name="tag">The schema type tag</param>
 /// <param name="writer">The writer which should be used to write the given type.</param>
 protected virtual void Write <S>(object value, Schema.Type tag, Writer <S> writer)
 {
     if (!(value is S))
     {
         throw TypeMismatch(value, tag.ToString(), typeof(S).ToString());
     }
     writer((S)value);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// A generic method to serialize primitive Avro types.
        /// </summary>
        /// <typeparam name="S">Type of the C# type to be serialized</typeparam>
        /// <param name="value">The value to be serialized</param>
        /// <param name="tag">The schema type tag</param>
        /// <param name="writer">The writer which should be used to write the given type.</param>
        protected void Write <S>(object value, Schema.Type tag, Writer <S> writer)
        {
            if (value == null)
            {
                value = default(S);
            }

            if (!(value is S))
            {
                throw TypeMismatch(value, tag.ToString(), typeof(S).ToString());
            }
            writer((S)value);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// A generic method to serialize primitive Avro types.
        /// </summary>
        /// <typeparam name="S">Type of the C# type to be serialized</typeparam>
        /// <param name="value">The value to be serialized</param>
        /// <param name="tag">The schema type tag</param>
        /// <param name="writer">The writer which should be used to write the given type.</param>
        private static void Write <S>(object value, Schema.Type tag, Writer <S> writer)
        {
            if (value == null)
            {
                value = default(S);
            }

            if (!(value is S))
            {
                throw new AvroTypeMismatchException(
                          $"[{typeof(S)}] required to write against [{tag.ToString()}] schema but found " + value.GetType());
            }

            writer((S)value);
        }