本文整理汇总了C#中IFormatter.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# IFormatter.Deserialize方法的具体用法?C# IFormatter.Deserialize怎么用?C# IFormatter.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFormatter
的用法示例。
在下文中一共展示了IFormatter.Deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
static object Deserialize(string filename,IFormatter formatter)
{
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
object obj = formatter.Deserialize(fs);
fs.Close();
return obj;
}
示例2: Clone
/// <summary>
/// Clone a object with via Serializing/Deserializing
/// using a implementation of IFormatter.
/// <seealso cref="IFormatter"/>
/// </summary>
/// <param name="obj">Object to clone</param>
/// <param name="formatter">IFormatter implementation in order to Serialize/Deserialize</param>
/// <returns>Clone object</returns>
public static object Clone(object obj, IFormatter formatter)
{
using (MemoryStream buffer = new MemoryStream())
{
formatter.Serialize(buffer, obj);
buffer.Position = 0;
return formatter.Deserialize(buffer);
}
}
示例3: Driver
void Driver (IFormatter formatter, A a)
{
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, a);
stream.Position = 0;
a.CheckSerializationStatus ();
a = (A) formatter.Deserialize (stream);
a.CheckDeserializationStatus ();
}
示例4: Deserialize
public static object Deserialize (string s, IFormatter b)
{
if (s == null || s == string.Empty)
return null;
using (MemoryStream ms = new MemoryStream ()) {
byte [] ba = HttpUtility.UrlDecodeToBytes (s);
ms.Write (ba, 0, ba.Length);
ms.Position = 0;
try {
return b.Deserialize (ms);
}
catch (Exception e) {
throw;
}
}
}
示例5: MmTaskSolver
public MmTaskSolver(byte[] problemData)
: base(problemData)
{
_formatter = new BinaryFormatter();
try
{
using (var memoryStream = new MemoryStream(problemData))
{
_minMaxProblem = (MmProblem) _formatter.Deserialize(memoryStream);
}
State = TaskSolverState.OK;
}
catch (Exception)
{
State = TaskSolverState.Error;
}
}
示例6: DeserializeList
/// <summary>
/// A general-purpose function to deserialize a list from a stream
/// </summary>
/// <param name="stream">The stream to read the data from</param>
/// <param name="formatter">The formatter to use</param>
/// <param name="list">The list to deserialize</param>
private static void DeserializeList(Stream stream, IFormatter formatter, IList list)
{
int count = (int)formatter.Deserialize(stream);
for (int idx = 0; idx != count; idx++)
{
list.Add(formatter.Deserialize(stream));
}
if (count != list.Count)
{
throw new Exception("List did not deserialize to correct size");
}
}
示例7: Method3
void Method3(Stream stream, IFormatter formatter)
{
Console.WriteLine("Method3 Start : UnBan User To User");
stream.Position = 0;
if (stream.Length > 0)
{
BanPair bP = (BanPair)(formatter.Deserialize(stream));
foreach (BanPair bPair in BanPairManager.BanPairs)
{
if (bPair.Id1 == bP.Id1 && bPair.Id2 == bP.Id2) { BanPairManager.BanPairs.Remove(bPair); break; }
}
string query = string.Format("delete from BanList where UserID1={0} and UserID2={1}", bP.Id1, bP.Id2);
SqlCommand command = new SqlCommand(query, DataBase.Sql);
command.ExecuteNonQuery();
Dictionary<Socket, ChatInfoDAL.User>.ValueCollection valUser = dictSocketUser.Values;
int numBanned;
bool online = false;
for (numBanned = 0; numBanned < valUser.Count; numBanned++)
{
if (valUser.ElementAt(numBanned).UserID == bP.Id2) { online = true; break; }
}
string nameBan = string.Empty;
foreach (ChatInfoDAL.User us in UserManager.Users)
{
if (us.UserID == bP.Id1) { nameBan = us.NickName; break; }
}
string nameBan2 = string.Empty;
foreach (ChatInfoDAL.User us in UserManager.Users)
{
if (us.UserID == bP.Id2) { nameBan2 = us.NickName; break; }
}
Action<string> action = MessageToInfoStackAdd;
string messa = String.Format("{0} разбанил {1}", nameBan, nameBan2);
infoStack.Dispatcher.Invoke(action, messa);
if (online)
{
Socket sctBanned = dictSocketUser.ElementAt(numBanned).Key;
byte[] code = Encoding.UTF8.GetBytes("07");
sctBanned.Send(code);
IFormatter formatter2 = new BinaryFormatter();
Stream stream2 = new MemoryStream();
string messageBan = String.Format("Пользователь {0} вас разбанил", nameBan);
formatter2.Serialize(stream2, messageBan);
byte[] buffer2 = new byte[1024];
stream2.Position = 0;
while (stream2.Position < stream2.Length)
{
int readCount = stream2.Read(buffer2, 0, 1024);
sctBanned.Send(buffer2, readCount, 0);
}
}
else
{
ChatInfoDAL.User userToSend = null;
foreach (ChatInfoDAL.User us in UserManager.Users)
{
if (us.UserID == bP.Id2) { userToSend = us; break; }
}
messInQueue.Add(new MessageQueue(userToSend, String.Format("Пользователь {0} вас разбанил", nameBan)));
}
}
}
示例8: DeserializeObject
static object DeserializeObject(IFormatter serializer, XmlNode element)
{
using (var memoryStream = new MemoryStream())
using (var xmlDictionaryWriter = XmlDictionaryWriter.CreateTextWriter(memoryStream))
{
element.WriteContentTo(xmlDictionaryWriter);
xmlDictionaryWriter.Flush();
memoryStream.Position = 0;
var deserializedObject = serializer.Deserialize(memoryStream);
return deserializedObject;
}
}
示例9: Load
/// <summary>
/// Load activity from the given stream
/// </summary>
/// <param name="stream">stream with serialized activity</param>
/// <param name="formatter">formatter to be used during deserialization</param>
/// <returns>deserialized activity</returns>
public static Activity Load (Stream stream, Activity outerActivity, IFormatter formatter) {
if (stream == null)
throw new ArgumentNullException ("stream");
if (formatter == null)
throw new ArgumentNullException ("formatter");
return (Activity)formatter.Deserialize (stream);
}
示例10: ApplyRestoreData
/// <summary>
/// Apply the dialog settings that have previously been serialized
/// </summary>
/// <param name="stream">The stream to apply the settings from</param>
/// <param name="formatter">The formatter to use</param>
private void ApplyRestoreData(Stream stream, IFormatter formatter)
{
Bounds = (Rectangle)formatter.Deserialize(stream);
ignoreCaseCheckBox.Checked = (bool)formatter.Deserialize(stream);
searchTypeComboBox.SelectedIndex = (int)formatter.Deserialize(stream);
searchHistoryComboBox.Text = (string)formatter.Deserialize(stream);
DeserializeList(stream, formatter, searchHistoryComboBox.Items);
replaceHistoryComboBox.Text = (string)formatter.Deserialize(stream);
DeserializeList(stream, formatter, replaceHistoryComboBox.Items);
replaceModeCheckBox.Checked = (bool)formatter.Deserialize(stream);
}
示例11: btn_load_Click
private void btn_load_Click(object sender, EventArgs e)
{
if (ofd1.ShowDialog() == DialogResult.OK)
{
openFileName = ofd1.FileName;
formatter = new BinaryFormatter();
stream = new FileStream(this.openFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
#region 重构棋盘
//初始化黑棋,创建父类
bzu1 = new BZu(pic_Bzu1, pic_chessboard, p_array, pnl_RedDied, 43, 205, stackPoint, stackPictureBox);
bzu2 = new BZu(pic_Bzu2, pic_chessboard, p_array, pnl_RedDied, 151, 205, stackPoint, stackPictureBox);
bzu3 = new BZu(pic_Bzu3, pic_chessboard, p_array, pnl_RedDied, 259, 205, stackPoint, stackPictureBox);
bzu4 = new BZu(pic_Bzu4, pic_chessboard, p_array, pnl_RedDied, 367, 205, stackPoint, stackPictureBox);
bzu5 = new BZu(pic_Bzu5, pic_chessboard, p_array, pnl_RedDied, 475, 205, stackPoint, stackPictureBox);
bpao1 = new BPao(pic_Bpao1, pic_chessboard, p_array, pnl_RedDied, 97, 151, stackPoint, stackPictureBox);
bpao2 = new BPao(pic_Bpao2, pic_chessboard, p_array, pnl_RedDied, 421, 151, stackPoint, stackPictureBox);
bju1 = new BJu(pic_Bju1, pic_chessboard, p_array, pnl_RedDied, 43, 43, stackPoint, stackPictureBox);
bju2 = new BJu(pic_Bju2, pic_chessboard, p_array, pnl_RedDied, 475, 43, stackPoint, stackPictureBox);
bma1 = new BMa(pic_Bma1, pic_chessboard, p_array, pnl_RedDied, 97, 43, stackPoint, stackPictureBox);
bma2 = new BMa(pic_Bma2, pic_chessboard, p_array, pnl_RedDied, 421, 43, stackPoint, stackPictureBox);
bxiang1 = new BXiang(pic_Bxiang1, pic_chessboard, p_array, pnl_RedDied, 151, 43, stackPoint, stackPictureBox);
bxiang2 = new BXiang(pic_Bxiang2, pic_chessboard, p_array, pnl_RedDied, 367, 43, stackPoint, stackPictureBox);
bshi1 = new BShi(pic_Bshi1, pic_chessboard, p_array, pnl_RedDied, 205, 43, stackPoint, stackPictureBox);
bshi2 = new BShi(pic_Bshi2, pic_chessboard, p_array, pnl_RedDied, 313, 43, stackPoint, stackPictureBox);
bjiang = new BJiang(pic_Bjiang, pic_chessboard, p_array, pnl_RedDied, 259, 43, stackPoint, stackPictureBox);
//初始化红棋,创建父类
rzu1 = new RZu(pic_Rzu1, pic_chessboard, p_array, pnl_BlackDied, 43, 367, stackPoint, stackPictureBox);
rzu2 = new RZu(pic_Rzu2, pic_chessboard, p_array, pnl_BlackDied, 151, 367, stackPoint, stackPictureBox);
rzu3 = new RZu(pic_Rzu3, pic_chessboard, p_array, pnl_BlackDied, 259, 367, stackPoint, stackPictureBox);
rzu4 = new RZu(pic_Rzu4, pic_chessboard, p_array, pnl_BlackDied, 367, 367, stackPoint, stackPictureBox);
rzu5 = new RZu(pic_Rzu5, pic_chessboard, p_array, pnl_BlackDied, 475, 367, stackPoint, stackPictureBox);
rpao1 = new RPao(pic_Rpao1, pic_chessboard, p_array, pnl_BlackDied, 97, 421, stackPoint, stackPictureBox);
rpao2 = new RPao(pic_Rpao2, pic_chessboard, p_array, pnl_BlackDied, 421, 421, stackPoint, stackPictureBox);
rju1 = new RJu(pic_Rju1, pic_chessboard, p_array, pnl_BlackDied, 43, 529, stackPoint, stackPictureBox);
rju2 = new RJu(pic_Rju2, pic_chessboard, p_array, pnl_BlackDied, 475, 529, stackPoint, stackPictureBox);
rma1 = new RMa(pic_Rma1, pic_chessboard, p_array, pnl_BlackDied, 97, 529, stackPoint, stackPictureBox);
rma2 = new RMa(pic_Rma2, pic_chessboard, p_array, pnl_BlackDied, 421, 529, stackPoint, stackPictureBox);
rxiang1 = new RXiang(pic_Rxiang1, pic_chessboard, p_array, pnl_BlackDied, 151, 529, stackPoint, stackPictureBox);
rxiang2 = new RXiang(pic_Rxiang2, pic_chessboard, p_array, pnl_BlackDied, 367, 529, stackPoint, stackPictureBox);
rshi1 = new RShi(pic_Rshi1, pic_chessboard, p_array, pnl_BlackDied, 205, 529, stackPoint, stackPictureBox);
rshi2 = new RShi(pic_Rshi2, pic_chessboard, p_array, pnl_BlackDied, 313, 529, stackPoint, stackPictureBox);
rjiang = new RJiang(pic_Rjiang, pic_chessboard, p_array, pnl_BlackDied, 259, 529, stackPoint, stackPictureBox);
r_count = (int)formatter.Deserialize(stream); b_count = (int)formatter.Deserialize(stream);
lab_bCount.Text = b_count.ToString();
lab_rCount.Text = r_count.ToString();
pic_chessboard.Enabled = (bool)formatter.Deserialize(stream);
whichside = (int)formatter.Deserialize(stream);
if (whichside == 1)
{
pic_whichside.Image = Image.FromFile(@"img\whichside_red.png");
}
else
{
pic_whichside.Image = Image.FromFile(@"img\whichside_black.png");
}
r_mint = (int)formatter.Deserialize(stream);
b_mint = (int)formatter.Deserialize(stream);
//计时器重写
int h, m, s;
string time;
s = r_mint % 60;
m = (int)r_mint / 60 % 60;
h = (int)r_mint / 60 / 60;
time = string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s);
lab_rTime.Text = time;
s = b_mint % 60;
m = (int)b_mint / 60 % 60;
h = (int)b_mint / 60 / 60;
time = string.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s);
lab_bTime.Text = time;
p_array = new PictureBox[2, 16] { { pic_Bzu1, pic_Bzu2, pic_Bzu3, pic_Bzu4, pic_Bzu5, pic_Bpao1, pic_Bpao2, pic_Bju1, pic_Bju2, pic_Bma1, pic_Bma2, pic_Bxiang1, pic_Bxiang2, pic_Bshi1, pic_Bshi2, pic_Bjiang },
{ pic_Rzu1, pic_Rzu2, pic_Rzu3, pic_Rzu4, pic_Rzu5, pic_Rpao1, pic_Rpao2, pic_Rju1, pic_Rju2, pic_Rma1, pic_Rma2, pic_Rxiang1, pic_Rxiang2, pic_Rshi1, pic_Rshi2, pic_Rjiang } };
//此数组纪录下所有棋,用于判断坐标 p_array[0,x]为黑棋 p_array[1,x]为红棋
/*
ChessPieces[,] cp_array = new ChessPieces[2, 16] { { bzu1, bzu2, bzu3, bzu4, bzu5, bpao1, bpao2, bju1, bju2, bma1, bma2, bxiang1, bxiang2, bshi1, bshi2, bjiang },
{ rzu1, rzu2, rzu3, rzu4, rzu5, rpao1, rpao2, rju1, rju2, rma1, rma2, rxiang1, rxiang2, rshi1, rshi2, rjiang } };
//此数组纪录下所有棋,用于判断坐标 cp_array[0,x]为黑棋 cp_array[1,x]为红棋
*/
for (int i = 0; i != 2; i++)//将所有棋子的picturebox变为圆形
{
for (int j = 0; j != 16; j++)
{ makePicRound(p_array[i, j]); }
}
int ind;
for (int i = 0; i != 2; i++)
{
for (int j = 0; j != 16; j++)
{
ind = (int)formatter.Deserialize(stream);
if (ind == 1) { p_array[i, j].Parent = pic_chessboard; }
else
{
//.........这里部分代码省略.........
示例12: Deserialize
/// <summary>
/// Recreate this tree from a serialized version.
/// </summary>
/// <param name="stream">the stream that contains the serialized tree.</param>
/// <param name="formatter">the formatter used to desrialize the stream.</param>
public void Deserialize(Stream stream, IFormatter formatter)
{
// Clear our tree:
this.Nodes.Clear();
KTreeView temp = formatter.Deserialize(stream) as KTreeView;
if (temp != null)
{
// copy the nodes from the temp to our tree:
foreach (TreeNode node in temp.Nodes)
{
this.Nodes.Add(KCommon.Utils.StreamCloner.Clone(node.Clone()) as TreeNode);
}
}
}
示例13: Load
//! Load the data.
public void Load(IFormatter Formatter, Stream Stream_)
{
m_PositionX = (int)Formatter.Deserialize(Stream_);
m_PositionY = (int)Formatter.Deserialize(Stream_);
m_Tiles = (he.TerrainTile[])Formatter.Deserialize(Stream_);
m_Properties = (Dictionary<ushort, he.TerrainTileProperty>)Formatter.Deserialize(Stream_);
// Load mesh
Mesh mesh = (Mesh)Resources.Load((string)Formatter.Deserialize(Stream_), typeof(Mesh));
GetComponent<MeshFilter>().mesh = mesh;
GetComponent<MeshCollider>().sharedMesh = mesh;
var mesh_renderer = GetComponent<MeshRenderer>();
// Set map material
int materials_length = (int)Formatter.Deserialize(Stream_);
for (int i = 0; i < materials_length; ++i)
mesh_renderer.sharedMaterial = Resources.Load((string)Formatter.Deserialize(Stream_), typeof(Material)) as Material;
// Load all non-moveables
foreach (var it in m_Properties)
{
if (it.Value.nonMoveable != null)
{
// Get tile
var tile = m_Tiles[it.Key];
GameObject non_moveable_go = utils.PrefabManager.Create("Items/Barrel");
var comp = non_moveable_go.GetComponent<NonMoveableObjectComponent>();
comp.Load(Formatter, Stream_);
AssociateNonMoveable(tile.x, tile.y, comp);
}
}
}
示例14: Benchmark
public void Benchmark(IFormatter formatter)
{
var ms = new MemoryStream();
Console.WriteLine(formatter.ToString());
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 5000; i++)
{
formatter.Serialize(ms, _graph);
ms.Position = 0;
}
Console.WriteLine("Size: " + ms.Length);
Console.WriteLine("Serialization: " + sw.Elapsed);
sw.Reset();
sw.Start();
for (int i = 0; i < 5000; i++)
{
formatter.Deserialize(ms);
ms.Position = 0;
}
Console.WriteLine("Deserialization: " + sw.Elapsed);
}
示例15: ReadObjectTree
/// <summary>
/// Deserializes the object tree from the underlying stream using the given formatter.
/// </summary>
/// <param name="formatter">The formatter to use when deserializing the object.</param>
/// <returns>The deserialized object.</returns>
public virtual Object ReadObjectTree(IFormatter formatter){
stream.Seek(0, SeekOrigin.Begin);
return formatter.Deserialize(stream);
}