Exemplo n.º 1
0
        public void TestReadInMemory()
        {
            var          serializer      = new LanguagePackSerializer();
            LanguagePack dictionary      = new LanguagePack(description, languageDictionary);
            LanguagePack splitDictionary = new LanguagePack(description, languageSplitDictionary);

            using (Stream stream = new MemoryStream())
            {
                serializer.Serialize(stream, dictionary);

                stream.Seek(0, SeekOrigin.Begin);
                var pack = serializer.DeserializeSplit(stream);

                CheckIsSame(dictionary, pack);
            }

            using (Stream stream = new MemoryStream())
            {
                serializer.Serialize(stream, splitDictionary);

                stream.Seek(0, SeekOrigin.Begin);
                var pack = serializer.DeserializePack(stream);

                CheckIsSame(splitDictionary, pack);
            }
        }
 /// <summary>
 /// 尝试读取到语言包,不返回异常;
 /// </summary>
 private bool TryDeserializePack(LanguagePackSerializer packSerializer, ILanguagePackInfo info, out LanguagePack languagePack)
 {
     using (var stream = info.GetInputStream())
     {
         try
         {
             if (IsReadAsSplitPack)
             {
                 languagePack = packSerializer.DeserializeSplit(stream);
             }
             else
             {
                 languagePack = packSerializer.DeserializePack(stream);
             }
             return(true);
         }
         catch (Exception ex)
         {
             Debug.LogWarning(string.Format("读取语言包[{0}]时失败!{1}", info, ex));
             languagePack = default(LanguagePack);
             return(false);
         }
     }
 }