Пример #1
0
 /// <summary>
 ///  This method provides the functionality to convert any object to the appropriate
 ///    type for this mapper. The default behaviour only handles null values, empty
 ///    strings and DBNull.Value and parses all three to null. This method should be
 ///    overridden in subtypes to parse values to the type you want.
 ///  </summary>
 /// <param name="valueToParse">The value to be attempted to parse</param>
 /// <param name="returnValue">the parsed value, if parsing was successful</param>
 /// <returns>True if the parsing was succesful, false if this mapper was unable to
 /// parse the valueToParse.</returns>
 public override bool TryParsePropValue(object valueToParse, out object returnValue)
 {
     if (base.TryParsePropValue(valueToParse, out returnValue))
     {
         return(true);
     }
     if (valueToParse is Image)
     {
         returnValue = valueToParse;
         return(true);
     }
     if (valueToParse is byte[])
     {
         returnValue = SerialisationUtilities.ByteArrayToObject((byte[])valueToParse);
         return(true);
     }
     if (valueToParse is String)
     {
         var bytes = Convert.FromBase64String((string)valueToParse);
         returnValue = new Bitmap(new MemoryStream(bytes));
         return(true);
     }
     returnValue = null;
     return(false);
 }
Пример #2
0
        public void TestTwoWayConversion()
        {
            Image image = (Image)_resourceManager.GetObject("TestJpeg");

            byte[] bytesOut  = SerialisationUtilities.ObjectToByteArray(image);
            Object objectOut = SerialisationUtilities.ByteArrayToObject(bytesOut);

            Assert.AreEqual(image.GetType(), objectOut.GetType());
        }