当前位置: 首页>>代码示例>>C#>>正文


C# System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize方法代码示例

本文整理汇总了C#中System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize方法的具体用法?C# System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize怎么用?C# System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Runtime.Serialization.Formatters.Binary.BinaryFormatter的用法示例。


在下文中一共展示了System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadFile

 public static void LoadFile()
 {
     try
     {
         recentProjects=new System.Collections.ArrayList(4);
         recentFiles=new System.Collections.ArrayList(4);
         System.IO.FileStream stream = new System.IO.FileStream("\\lastfiles.dat", System.IO.FileMode.Open);
         System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
         recentProjects = (System.Collections.ArrayList)formatter.Deserialize( stream );
         recentFiles = (System.Collections.ArrayList)formatter.Deserialize( stream );
         stream.Close();
     }
     catch{}
 }
开发者ID:shadabahmed,项目名称:megaide,代码行数:14,代码来源:Recent.cs

示例2: TestSerializeSchemaPropertyValueCollection

		public void TestSerializeSchemaPropertyValueCollection()
		{
			System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
			System.IO.MemoryStream ms = new System.IO.MemoryStream();
			SchemaPropertyValueCollection obj1 = new SchemaPropertyValueCollection();

			SCGroup group = SCObjectGenerator.PrepareGroupObject();

			foreach (string key in group.Properties.GetAllKeys())
			{
				obj1.Add(group.Properties[key]);
			}

			bf.Serialize(ms, obj1);
			ms.Seek(0, System.IO.SeekOrigin.Begin);

			var obj2 = (SchemaPropertyValueCollection)bf.Deserialize(ms);

			Assert.AreEqual(obj1.Count, obj2.Count);

			var keys1 = obj1.GetAllKeys();

			foreach (var key in keys1)
			{
				Assert.IsTrue(obj2.ContainsKey(key));
				Assert.AreEqual(obj1[key].StringValue, obj2[key].StringValue);
			}
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:28,代码来源:SerializableTest.cs

示例3: Load

        private const string PATH_TO_DAT_FILE = "./joueurs.dat"; //Répertoire courrant.

        #endregion Fields

        #region Methods

        /// <summary>
        /// Charge un fichier contenant tous les joueurs.
        /// </summary>
        /// <returns>La liste de joueurs s'il y en a, sinon null.</returns>
        public static List<Joueur> Load()
        {
            List<Joueur> joueurs = null;

            if (File.Exists(PATH_TO_DAT_FILE))
            {
                try
                {
                    using (Stream stream = File.Open(PATH_TO_DAT_FILE, FileMode.Open))
                    {
                        stream.Position = 0;
                        var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        joueurs = (List<Joueur>)bformatter.Deserialize(stream);
                    }
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Le fichier est invalide.");
                }
                catch (DirectoryNotFoundException)
                {
                    MessageBox.Show("Répertoire introuvable");
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("Le fichier n'existe pas.");
                }
                catch (IOException)
                {
                    MessageBox.Show("Problème lors de la lecture du fichier.");
                }
            }

            return joueurs;
        }
开发者ID:chef-marmotte,项目名称:jeu-blackjack,代码行数:45,代码来源:JoueurParser.cs

示例4: ByteArrayToObject

 /// <summary>
 /// 扩展方法:将二进制byte[]数组反序列化为对象-通过系统提供的二进制流来完成反序列化
 /// </summary>
 /// <param name="SerializedObj">待反序列化的byte[]数组</param>
 /// <param name="ThrowException">是否抛出异常</param>
 /// <returns>返回结果</returns>
 public static object ByteArrayToObject(this byte[] SerializedObj, bool ThrowException)
 {
     if (SerializedObj == null)
     {
         return null;
     }
     else
     {
         try
         {
             System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
             System.IO.MemoryStream stream = new System.IO.MemoryStream(SerializedObj);
             object obj = formatter.Deserialize(stream);
             return obj;
         }
         catch (System.Exception ex)
         {
             if (ThrowException)
             {
                 throw ex;
             }
             else
             {
                 return null;
             }
         }
     }
 }
开发者ID:JBTech,项目名称:Dot.Utility,代码行数:34,代码来源:ObjectToByteArrayExtension.cs

示例5: SyncFolderPairs

 public void SyncFolderPairs(string ConfigFileName, int index, bool previewOnly)
 {
     SyncToy.SyncEngineConfig SEConfig = null;
     ArrayList EngineConfigs = new ArrayList();
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     try
     {
         using (StreamReader sr = new StreamReader(ConfigFileName))
         {
             do
             {
                 SEConfig = (SyncToy.SyncEngineConfig)bf.Deserialize(sr.BaseStream);
                 EngineConfigs.Add(SEConfig);
             }
             while (sr.BaseStream.Position < sr.BaseStream.Length);
             sr.Close();
         }
         if (index != -1)
         {
             SyncFolderPair((SyncToy.SyncEngineConfig)EngineConfigs[index], previewOnly);
         }
         else
         {
             foreach (SyncToy.SyncEngineConfig Config in EngineConfigs)
             {
                 SyncFolderPair(Config, previewOnly);
             }
         }
        }
     catch (Exception ex)
     {
         Console.WriteLine("SyncFolderPairs Exception -> {0}", ex.Message);
     }
 }
开发者ID:KurtDeGreeff,项目名称:SyncToy,代码行数:34,代码来源:SyncToyRunner.cs

示例6: MainWindow

        public MainWindow()
        {
            InitializeComponent();
            //if (System.IO.Directory.Exists(cardPath) == false)
            //{
            //    System.IO.Directory.CreateDirectory(cardPath);
            //}
            if (System.IO.File.Exists(cardPath + "cardList") == false)
            {
                DownloadAllCardSet();
            }
            else
            {
                try
                {
                    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter reader = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    System.IO.FileStream file = System.IO.File.OpenRead(cardPath + "cardList");
                    card.cardList = (List<card>)reader.Deserialize(file);
                    file.Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Your card database seems to be corrupted, we will redownload it");
                    DownloadAllCardSet();
                }

            }
            if (System.IO.File.Exists(cardPath + "cardCollection") == true)
            {
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter reader = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                System.IO.FileStream file = System.IO.File.OpenRead(cardPath + "cardCollection");
                card.MyCollection = (List<card>)reader.Deserialize(file);
                file.Close();
            }
        }
开发者ID:Folkstorm,项目名称:My-Heartstone-cards,代码行数:35,代码来源:MainWindow.xaml.cs

示例7: GetStock

        public Stock GetStock(StockName stockName, DateTime startDate, DateTime endDate)
        {
            string dir = String.Format(@"..\..\StockData\Yahoo");
            string filename = String.Format("{0}.stock", stockName);
            var fullPath = Path.Combine(dir, filename);

            List<IStockEntry> rates;
            if (!File.Exists(fullPath))
            {
                rates = GetStockFromRemote(stockName, startDate, endDate);
                Directory.CreateDirectory(dir);
                using (Stream stream = File.Open(fullPath, FileMode.Create))
                {
                    var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    bformatter.Serialize(stream, rates);
                }

            }
            else
            {
                using (Stream stream = File.Open(fullPath, FileMode.Open))
                {
                    var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    rates = (List<IStockEntry>) bformatter.Deserialize(stream);
                }
            }
            var stock = new Stock(stockName, rates);
            return stock;
        }
开发者ID:ilan84,项目名称:ZulZula,代码行数:29,代码来源:YahooDataProvider.cs

示例8: Deserialize

        public static Message Deserialize(NetworkStream ns)
        {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

            object obj = bf.Deserialize(ns);
            return (Message)obj;
        }
开发者ID:Xmindz,项目名称:ProjectTalk,代码行数:7,代码来源:Message.cs

示例9: GetSimilarity

        public static double[] GetSimilarity(double[] a, double[] b)
        {
            if (s_simi == null)
            {
                s_simi = new SimilarityAnalysis();
                s_simi.setOptions(new string[] { "-T", "first-1", "-e", "20", "-r", "3", "-f", "false" });

                if (System.IO.File.Exists(CacheFileName))
                {
                    using (var file = System.IO.File.Open(CacheFileName, System.IO.FileMode.Open))
                    {
                        var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        m_cache = bf.Deserialize(file) as Dictionary<double[], double[]>;
                    }
                }
                else
                {
                    m_cache = new Dictionary<double[], double[]>();
                }
            }

            //double[] c = new double[a.Length + b.Length];
            //a.CopyTo(c, 0);
            //b.CopyTo(c, a.Length);
            //if (m_cache.ContainsKey(c))
            //    return m_cache[c];

            Instances instance = CreateInstanceOnFly(a, b);
            s_simi.analyze(instance);

            double[] ret = new double[] { s_simi.m_distancesFreq[1][0], s_simi.m_distancesTime[1][0] };
            //m_cache[c] = ret;

            return ret;
        }
开发者ID:wushian,项目名称:MLEA,代码行数:35,代码来源:SimilarityAnalysis.cs

示例10: Application_AcquireRequestState

        //void global_asax_AcquireRequestState(object sender, EventArgs e)
        void Application_AcquireRequestState(object sender, EventArgs e)
        {
            // Code that runs when a new session is started
            // get the security cookie
            HttpCookie cookie = Request.Cookies.Get(FormsAuthentication.FormsCookieName);

            if (cookie != null)
            {
                // we got the cookie, so decrypt the value
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);

                if (ticket.Expired)
                {
                    // the ticket has expired - force user to login
                    FormsAuthentication.SignOut();
                    //Response.Redirect("~/Security/Login.aspx");
                }
                else
                {
                    // ticket is valid, set HttpContext user value
                    System.IO.MemoryStream buffer = new System.IO.MemoryStream(Convert.FromBase64String(ticket.UserData));
                    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    HttpContext.Current.User = (System.Security.Principal.IPrincipal)formatter.Deserialize(buffer);
                }
            }
        }
开发者ID:johnval990,项目名称:ISOA,代码行数:27,代码来源:Global.asax.cs

示例11: Fetch

 /// <summary>
 /// Get an existing business object.
 /// </summary>
 /// <param name="request">The request parameter object.</param>
 public byte[] Fetch(byte[] req)
 {
   var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
   Csla.Server.Hosts.WcfBfChannel.FetchRequest request;
   using (var buffer = new System.IO.MemoryStream(req))
   {
     request = (Csla.Server.Hosts.WcfBfChannel.FetchRequest)formatter.Deserialize(buffer);
   }
   Csla.Server.DataPortal portal = new Csla.Server.DataPortal();
   object result;
   try
   {
     result = portal.Fetch(request.ObjectType, request.Criteria, request.Context);
   }
   catch (Exception ex)
   {
     result = ex;
   }
   var response = new WcfResponse(result);
   using (var buffer = new System.IO.MemoryStream())
   {
     formatter.Serialize(buffer, response);
     return buffer.ToArray();
   }
 }
开发者ID:BiYiTuan,项目名称:csla,代码行数:29,代码来源:WcfBfPortal.cs

示例12: TestBulkDeletionResultsSerializable

        public void TestBulkDeletionResultsSerializable()
        {
            var successfulObjects = new[] { "/container/object1", "/container/object2" };
            var failedObjects =
                new[]
                {
                    new BulkDeletionFailedObject("/badContainer/object3", new Status((int)HttpStatusCode.BadRequest, "invalidContainer")),
                    new BulkDeletionFailedObject("/container/badObject", new Status((int)HttpStatusCode.BadRequest, "invalidName"))
                };
            BulkDeletionResults results = new BulkDeletionResults(successfulObjects, failedObjects);
            BinaryFormatter formatter = new BinaryFormatter();
            using (Stream stream = new MemoryStream())
            {
                formatter.Serialize(stream, results);
                stream.Position = 0;
                BulkDeletionResults deserialized = (BulkDeletionResults)formatter.Deserialize(stream);
                Assert.IsNotNull(deserialized);

                Assert.IsNotNull(deserialized.SuccessfulObjects);
                Assert.AreEqual(successfulObjects.Length, deserialized.SuccessfulObjects.Count());
                for (int i = 0; i < successfulObjects.Length; i++)
                    Assert.AreEqual(successfulObjects[i], deserialized.SuccessfulObjects.ElementAt(i));

                Assert.IsNotNull(deserialized.FailedObjects);
                Assert.AreEqual(failedObjects.Length, deserialized.FailedObjects.Count());
                for (int i = 0; i < failedObjects.Length; i++)
                {
                    Assert.IsNotNull(deserialized.FailedObjects.ElementAt(i));
                    Assert.AreEqual(failedObjects[i].Object, deserialized.FailedObjects.ElementAt(i).Object);
                    Assert.IsNotNull(deserialized.FailedObjects.ElementAt(i).Status);
                    Assert.AreEqual(failedObjects[i].Status.Code, deserialized.FailedObjects.ElementAt(i).Status.Code);
                    Assert.AreEqual(failedObjects[i].Status.Description, deserialized.FailedObjects.ElementAt(i).Status.Description);
                }
            }
        }
开发者ID:alanquillin,项目名称:openstack.net,代码行数:35,代码来源:SerializationTests.cs

示例13: Load

        // Pelaajien lataaminen tiedostosta
        public List<Pelaaja> Load(string filepath)
        {
            // palautusarvo
            List<Pelaaja> players = new List<Pelaaja>();
            // haetaan pääte
            string ext = Path.GetExtension(filepath);

            using (Stream stream = File.Open(filepath, FileMode.Open))
            {
                // tarkastetaan tiedostopäätteen perusteella
                // miten sitä käsitellään
                // HOX HUONO TAPA, tiedostopäätteellä ei oikeasti ole merkitystä
                switch (ext)
                {
                    case ".xml":
                        XmlSerializer serializer = new XmlSerializer(typeof(List<Pelaaja>));
                        players = (List<Pelaaja>)serializer.Deserialize(stream);
                        break;

                    case ".bin":
                        var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        players = (List<Pelaaja>)bformatter.Deserialize(stream);
                        break;

                    default:
                        throw new Exception("Extension \"" + ext + "\" is not supported");
                }
            }

            return players;
        }
开发者ID:JoniKukko,项目名称:IIO11300,代码行数:32,代码来源:FileHandler.cs

示例14: LoadFields

 public static void LoadFields()
 {
     IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     Stream stream = new FileStream("FieldList.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
     FieldList = (List<Field>)formatter.Deserialize(stream);
     stream.Close();
 }
开发者ID:OrigamiSamurai,项目名称:HeroBarn,代码行数:7,代码来源:ControlEngine.cs

示例15: LoadGrammar_ToolButton_Click

        private void LoadGrammar_ToolButton_Click( object sender, EventArgs e )
        {
            if( this.LoadGrammar_Dialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK )
            {
                try
                {
                    SyntacticAnalysis.Grammar grammar;
                    using( var stream = System.IO.File.OpenRead(this.LoadGrammar_Dialog.FileName) )
                    {
                        var bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        grammar = (SyntacticAnalysis.Grammar)bf.Deserialize(stream);
                    }

                    this.Editor.Grammar = grammar;
                }
                catch( Exception ex )
                {
                    MessageBox.Show(
                        this,
                        ex.Message,
                        "Hiba nyelvtan betöltése közben",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
            }
        }
开发者ID:mqrelly,项目名称:Syntan,代码行数:26,代码来源:GrammarForm.cs


注:本文中的System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。