public static byte[] ToBson <T>(this IScope schema, T obj)
        {
            var output = new MemoryStream();

            Write(schema, FormatFactory.CreateWriter(output, Format.Bson), obj);
            output.Close();
            return(output.ToArray());
        }
        /// <summary>
        /// Serializes given object to string of specified format.
        /// </summary>
        /// <typeparam name="T">The object type.</typeparam>
        /// <param name="schema">Serialization schema.</param>
        /// <param name="obj">The object to serialize.</param>
        /// <param name="format">The output format.</param>
        /// <returns>Output string.</returns>
        public static string ToString <T>(this IScope schema, T obj, Format format)
        {
            var output = new StringBuilder();

            using (var textWriter = new StringWriter(output))
                using (var writer = FormatFactory.CreateWriter(textWriter, format))
                    Write(schema, writer, obj);
            return(output.ToString());
        }