Short sample :

using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
namespace Serializable
{
    [Serializable]
    public class MySampleClass
    {
        public virtual string Message { get; set; }
    }
    public class SampleHolder
    {
        private byte[] _sample;
        public virtual MySampleClass Sample
        {
            get
            {
                if (_sample == null)
                    return null;
                return formatter.Deserialize(new MemoryStream(_sample)) as
MySampleClass;
            }
            set
            {
                var stream = new MemoryStream();
                formatter.Serialize(stream, value);
                _sample = stream.GetBuffer();
            }
        }
        private readonly BinaryFormatter formatter = new BinaryFormatter();
    }
    [TestFixture]
    public class Test
    {
        [Test]
        public void Works()
        {
            var sample = new MySampleClass {Message = "Hello World!"};
            var holder = new SampleHolder {Sample = sample};
            Assert.AreEqual(sample.Message, holder.Sample.Message);
        }
    }
}
-Markus


2009/3/19 Markus Zywitza <[email protected]>

> Take a look at the BinaryFormatter and MemoryStream classes.
>
> -Markus
>
> 2009/3/19 klawry <[email protected]>
>
>
>> Markus,
>>
>> Thanks for your reply.  I think you're on the right track - I found
>> another post mentioning the use of Byte[] with BinaryBlob.
>>
>> The only problem is that I can't find any documentation anywhere on
>> how to convert an object to System.Byte[].  It sounds like a fairly
>> straightforward thing to do, but a direct type cast isn't allowed and
>> the Convert.ToByte options don't include byte arrays.  Can you post or
>> point me to some sample code?  Thanks again!
>>
>> Kevin
>>
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to