Apache.Shiro.IO.DefaultSerializer.Serialize C# (CSharp) Method

Serialize() public method

public Serialize ( object o ) : byte[]
o object
return byte[]
        public byte[] Serialize(object o)
        {
            if (o == null)
            {
                throw new ArgumentNullException("o");
            }

            var type = o.GetType();
            if (!type.IsDefined(typeof(SerializableAttribute), true))
            {
                throw new ArgumentException(
                    string.Format("The provided object cannot be serialized; [{0}] is not serializable", type));
            }

            using (var stream = new MemoryStream())
            {
                var buffer = new BufferedStream(stream);
                var formatter = new BinaryFormatter();

                formatter.Serialize(buffer, o);
                buffer.Flush();

                return stream.GetBuffer();
            }
        }
DefaultSerializer