예제 #1
0
        public static LocalizedString SafeDeserialize(byte[] bytes)
        {
            if (bytes == null)
            {
                return(default(LocalizedString));
            }
            BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(new SafeLocalizedStringSerializer.ValidatingBinder());
            object          obj;

            using (MemoryStream memoryStream = new MemoryStream(bytes))
            {
                try
                {
                    obj = binaryFormatter.Deserialize(memoryStream);
                }
                catch (BlockedTypeException ex)
                {
                    SafeLocalizedStringSerializer.CreateWatson(ex);
                    return(ex.LocalizedString);
                }
            }
            if (!(obj is LocalizedString))
            {
                return(new LocalizedString((obj == null) ? "null" : obj.ToString()));
            }
            return((LocalizedString)obj);
        }
예제 #2
0
 public static byte[] SafeSerialize(LocalizedString localizedString)
 {
     if (localizedString.Equals(default(LocalizedString)))
     {
         return(null);
     }
     byte[] result;
     try
     {
         BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(new SafeLocalizedStringSerializer.ValidatingBinder());
         using (MemoryStream memoryStream = new MemoryStream())
         {
             binaryFormatter.Serialize(memoryStream, localizedString);
             result = memoryStream.ToArray();
         }
     }
     catch (BlockedTypeException ex)
     {
         SafeLocalizedStringSerializer.CreateWatson(ex);
         result = SafeLocalizedStringSerializer.SafeSerialize(new LocalizedString(localizedString.ToString()));
     }
     return(result);
 }