本文整理汇总了C#中MonoDevelop.Core.Serialization.XmlDataSerializer.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDataSerializer.Serialize方法的具体用法?C# XmlDataSerializer.Serialize怎么用?C# XmlDataSerializer.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoDevelop.Core.Serialization.XmlDataSerializer
的用法示例。
在下文中一共展示了XmlDataSerializer.Serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializationDoubleRoundtrip
public void SerializationDoubleRoundtrip ()
{
var bag = new PropertyBag ();
var t = new SerializableObject {
SomeValue = "test1"
};
bag.SetValue ("foo", t);
var w = new StringWriter ();
var ser = new XmlDataSerializer (new DataContext ());
ser.Serialize (w, bag);
var data = w.ToString ();
SerializableObject.CreationCount = 0;
bag = ser.Deserialize<PropertyBag> (new StringReader (data));
// SerializableObject is not instantiated if not queried
Assert.AreEqual (0, SerializableObject.CreationCount);
w = new StringWriter ();
ser.Serialize (w, bag);
data = w.ToString ();
bag = ser.Deserialize<PropertyBag> (new StringReader (data));
// SerializableObject is not instantiated if not queried
Assert.AreEqual (0, SerializableObject.CreationCount);
t = bag.GetValue<SerializableObject> ("foo");
Assert.NotNull (t);
Assert.AreEqual ("test1", t.SomeValue);
}
示例2: SaveContents
public void SaveContents (string fileName)
{
using (StreamWriter writer = new StreamWriter (fileName)) {
XmlDataSerializer serializer = new XmlDataSerializer (MonoDevelop.Projects.Services.ProjectService.DataContext);
serializer.Serialize (writer, this);
}
}
示例3: SaveConfig
public static void SaveConfig ()
{
if (configuration != null) {
XmlDataSerializer s = new XmlDataSerializer (dataContext);
using (var wr = new XmlTextWriter (File.CreateText (ConfigFile))) {
wr.Formatting = Formatting.Indented;
s.Serialize (wr, configuration, typeof(AddinConfig));
}
}
}
示例4: SaveConfig
static void SaveConfig ()
{
try {
XmlDataSerializer ser = new XmlDataSerializer (new DataContext ());
StreamWriter sw = new StreamWriter (configFile);
using (sw) {
ser.Serialize (new XmlTextWriter (sw), config, typeof(AddinAuthoringServiceConfig));
}
}
catch (Exception ex) {
LoggingService.LogError ("Could not save add-in authoring service configuration", ex);
}
}
示例5: SerializeObjectToString
public static string SerializeObjectToString(object o)
{
LogUtil log = new LogUtil ("Util.Serialization");
// log.DEBUG("Serializing - " + o.ToString());
//StringBuilder resultString;
context.IncludeType (o.GetType ());
XmlDataSerializer ser = new XmlDataSerializer (context);
//XmlTextWriter xtw = new XmlTextWriter(Console.Out);
TextWriter serWriter = new StringWriter ();
XmlTextWriter xtw = new XmlTextWriter (serWriter);
ser.Serialize (xtw, o);
string serializedString = serWriter.ToString ();
//serializedString = serReader.ReadToEnd();
//log.DEBUG("The serialized string is - " + serializedString);
return serializedString;
}
示例6: SaveUserTasks
internal static void SaveUserTasks (IWorkspaceObject item)
{
string fileToSave = GetUserTasksFilename ((WorkspaceItem)item);
try {
List<Task> utasks = new List<Task> (userTasks.GetItemTasks (item, true));
if (utasks.Count == 0) {
if (File.Exists (fileToSave))
File.Delete (fileToSave);
} else {
XmlDataSerializer serializer = new XmlDataSerializer (new DataContext ());
serializer.Serialize (fileToSave, utasks);
}
} catch (Exception ex) {
LoggingService.LogWarning ("Could not save user tasks: " + fileToSave, ex);
}
}
示例7: SaveConfiguration
public static void SaveConfiguration ()
{
if (configuration != null) {
XmlDataSerializer ser = new XmlDataSerializer (dataContext);
XmlTextWriter tw = new XmlTextWriter (new StreamWriter (ConfigFile));
tw.Formatting = Formatting.Indented;
try {
ser.Serialize (tw, configuration, typeof (VersionControlConfiguration));
} finally {
tw.Close ();
}
}
}
示例8: WriteSolutionEntityItem
void WriteSolutionEntityItem (FilePath actualFile, FilePath outFile, object node, IProgressMonitor monitor)
{
StreamWriter sw = new StreamWriter (outFile);
try {
monitor.BeginTask (string.Format (GettextCatalog.GetString("Saving solution item: {0}"), actualFile), 1);
XmlDataSerializer ser = new XmlDataSerializer (MD1ProjectService.DataContext);
ser.SerializationContext.BaseFile = actualFile;
ser.SerializationContext.ProgressMonitor = monitor;
ser.Serialize (sw, node, typeof(SolutionEntityItem));
} catch (Exception ex) {
monitor.ReportError (string.Format (GettextCatalog.GetString ("Could not save solution item: {0}"), actualFile), ex);
} finally {
monitor.EndTask ();
sw.Close ();
}
}
示例9: WriteWorkspaceItem
void WriteWorkspaceItem (FilePath actualFile, FilePath outFile, WorkspaceItem item, IProgressMonitor monitor)
{
Workspace ws = item as Workspace;
if (ws != null) {
monitor.BeginTask (null, ws.Items.Count);
try {
foreach (WorkspaceItem it in ws.Items) {
it.Save (monitor);
monitor.Step (1);
}
} finally {
monitor.EndTask ();
}
}
StreamWriter sw = new StreamWriter (outFile);
try {
monitor.BeginTask (GettextCatalog.GetString ("Saving item: {0}", actualFile), 1);
XmlTextWriter tw = new XmlTextWriter (sw);
tw.Formatting = Formatting.Indented;
XmlDataSerializer ser = new XmlDataSerializer (MD1ProjectService.DataContext);
ser.SerializationContext.BaseFile = actualFile;
ser.SerializationContext.ProgressMonitor = monitor;
ser.Serialize (sw, item, typeof(WorkspaceItem));
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not save item: {0}", actualFile), ex);
throw;
} finally {
monitor.EndTask ();
sw.Close ();
}
}
示例10: WriteProject
void WriteProject (FilePath actualFile, FilePath outFile, Project project, IProgressMonitor monitor)
{
StreamWriter sw = new StreamWriter (outFile);
try {
monitor.BeginTask (GettextCatalog.GetString("Saving project: {0}", actualFile), 1);
XmlDataSerializer ser = new XmlDataSerializer (MD1ProjectService.DataContext);
ser.SerializationContext.BaseFile = actualFile;
ser.SerializationContext.ProgressMonitor = monitor;
ser.Serialize (sw, project, typeof(Project));
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not save project: {0}", actualFile), ex);
throw;
} finally {
monitor.EndTask ();
sw.Close ();
}
}
示例11: Write
public XmlElement Write ()
{
XmlDataSerializer ser = new XmlDataSerializer (new DataContext ());
ser.Namespace = MSBuildProject.Schema;
var sw = new StringWriter ();
ser.Serialize (new XmlTextWriter (sw), this);
XmlDocument doc = new XmlDocument ();
doc.LoadXml (sw.ToString ());
var elem = doc.DocumentElement;
doc.RemoveChild (elem);
return elem;
}
示例12: SaveViews
public void SaveViews ()
{
try {
XmlDataSerializer ser = new XmlDataSerializer (new DataContext ());
ser.Serialize (ConfigFile, views);
} catch (Exception ex) {
LoggingService.LogError ("Error while saving monitor-views.xml", ex);
}
}
示例13: SaveGeneratedFrameworkInfo
internal void SaveGeneratedFrameworkInfo ()
{
if (GeneratedFrameworksFile != null) {
Console.WriteLine ("Saving frameworks file: " + GeneratedFrameworksFile);
using (StreamWriter sw = new StreamWriter (GeneratedFrameworksFile)) {
XmlTextWriter tw = new XmlTextWriter (sw);
tw.Formatting = Formatting.Indented;
XmlDataSerializer ser = new XmlDataSerializer (new DataContext ());
ser.Serialize (tw, frameworks);
}
XmlDocument doc = new XmlDocument ();
doc.Load (GeneratedFrameworksFile);
doc.DocumentElement.InsertBefore (doc.CreateComment ("This file has been autogenerated. DO NOT MODIFY!"), doc.DocumentElement.FirstChild);
doc.Save (GeneratedFrameworksFile);
}
}
示例14: SaveGlobalCustomExecutionModes
static void SaveGlobalCustomExecutionModes()
{
if (globalModes == null)
return;
try {
XmlDataSerializer ser = new XmlDataSerializer (GetDataContext ());
FilePath file = UserProfile.Current.ConfigDir.Combine ("custom-command-modes.xml");
ser.Serialize (file, globalModes, typeof(CustomExecutionModes));
} catch (Exception ex) {
LoggingService.LogError ("Could not save global custom execution modes.", ex);
}
}
示例15: SaveConfiguration
public static void SaveConfiguration ()
{
if (configuration != null) {
XmlDataSerializer ser = new XmlDataSerializer (dataContext);
using (var tw = new XmlTextWriter (File.CreateText (ConfigFile))) {
tw.Formatting = Formatting.Indented;
ser.Serialize (tw, configuration, typeof (VersionControlConfiguration));
}
}
}