本文整理汇总了C#中Serializer.SerializeObject方法的典型用法代码示例。如果您正苦于以下问题:C# Serializer.SerializeObject方法的具体用法?C# Serializer.SerializeObject怎么用?C# Serializer.SerializeObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serializer
的用法示例。
在下文中一共展示了Serializer.SerializeObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveRule
public void SaveRule()
{
var dal = new DAL();
var bonds = dal.GetList();
if (bonds.Count == 0)
{
const string message = @"You do not have any bonds to Save, thus I am unable "
+ @" to save any bonds. Please add some bonds before Saving";
MessageBox.Show(message);
return;
}
var dlg = new SaveFileDialog { FileName = "Prize Bond Manager",
DefaultExt = ".pbm", Filter = @"Prize Bond Manager Files (.pbm)|*.pbm" };
// Show save file dialog box
var result = dlg.ShowDialog();
// Process save file dialog box results
if (result == DialogResult.OK)
{
// Save document
string filename = dlg.FileName;
var serializer = new Serializer();
var objectToSerialize = new ObjectToSerialize { Bonds = bonds };
serializer.SerializeObject(filename, objectToSerialize);
}
}
示例2: deleteButton_Click
private void deleteButton_Click(object sender, EventArgs e)
{
downloadedTrailers.RemoveAt(historyListBox.SelectedIndex);
historyListBox.DataSource = null;
historyListBox.DataSource = downloadedTrailers;
// Save new list
downloadedTrailers = (List<string>)historyListBox.DataSource;
Serializer serializer = new Serializer();
serializer.SerializeObject(Application.StartupPath + "\\trailerDB.txt", trailerDBobject);
}
示例3: runwork
// Thread to scan
private void runwork()
{
// Log in again
if (!login())
{
SetStatus(statusWindow, "Will try to log on again in 10 seconds");
hourTimer.Change(10000, 1000 * 60 * 60 * 4);
scanner.Abort();
}
try
{
// List to save movies to db file
List<string> downloadedTrailers = new List<string>();
ObjectToSerialize trailerDBobject = new ObjectToSerialize();
trailerDBobject.DownloadedTrailers = downloadedTrailers;
// Scan for trailers
SetStatus(statusWindow, "Scanning for new Trailers");
string URL = "http://www.trailerfreaks.com/";
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(new System.Uri(URL));
HttpWebResponse webres = (HttpWebResponse)webreq.GetResponse();
Stream resStream = webres.GetResponseStream();
string response = new StreamReader(resStream).ReadToEnd();
// Find trailer
string trailerStart = "a href =\"trai"; string toFind; string trailerName; string trailerDescription;
string trailerDate; string trailerActors; string trailerNameClean; string trailerDetailsURL;
int startindex, endindex;
//int numToGet = 10000;
//if (!numTrailersToGet.Equals("All"))
// numToGet = int.Parse(numTrailersToGet);
//int count = 0;
//while ((startindex = response.IndexOf(trailerStart)) > -1 && count < numToGet)
while ((startindex = response.IndexOf(trailerStart)) > -1)
{
bool skip = false;
if (startindex > -1)
{
response = response.Substring(startindex);
}
else
{
SetStatus(statusWindow, "Error Finding Trailer Page Links");
SetStatus(statusWindow, "Scanning aborted.");
enableControls(true);
scanner.Abort();
}
toFind = "title=\"";
startindex = response.IndexOf(toFind);
if (startindex > -1)
{
startindex += toFind.Length; // Move to starting position of new Trailer
}
else
{
SetStatus(statusWindow, "Error parsing for Trailer Name");
continue;
}
endindex = response.IndexOf("\"", startindex);
trailerName = response.Substring(startindex, endindex - startindex).Trim();
// Remove Year
trailerName = trailerName.Remove(trailerName.LastIndexOf(" "));
trailerNameClean = replaceSpecials(trailerName);
trailerNameClean = trailerNameClean.Remove(trailerNameClean.LastIndexOf(" "));
SetStatus(statusWindow, "Found Trailer: " + trailerName);
response = response.Substring(endindex);
// Check if it exists already in flat file
string trailerDB = Application.StartupPath + "\\trailerDB.txt";
if (!File.Exists(trailerDB))
{
if (verbose)
SetStatus(statusWindow, "New DB Created and will add Trailer after successfull download");
}
else
{
Serializer serializer = new Serializer();
trailerDBobject = serializer.DeSerializeObject(Application.StartupPath + "\\trailerDB.txt");
downloadedTrailers = trailerDBobject.DownloadedTrailers;
if (downloadedTrailers.Contains(trailerName + GetText(formatBox)))
{
SetStatus(statusWindow, "Already Downloaded, Skipping Trailer");
skip = true;
}
else
{
if (verbose)
SetStatus(statusWindow, "Not in DB will add Trailer after successfull download");
}
}
if (!skip)
{
// Get description
toFind = "<a href=\"";
startindex = response.IndexOf(toFind);
if (startindex > -1)
{
//.........这里部分代码省略.........
示例4: ToFile
public override void ToFile()
{
Serializer serializer = new Serializer();
serializer.SerializeObject<TerrainScreen>("save.txt", this);
}