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


C# XmlDataSerializer.Serialize方法代码示例

本文整理汇总了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);
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:33,代码来源:PropertyBagTests.cs

示例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);
			}
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:7,代码来源:ToolboxConfiguration.cs

示例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)); 
         }
     }
 }
开发者ID:taiste,项目名称:ViewInAndroidStudio,代码行数:10,代码来源:AddInPreferences.cs

示例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);
			}
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:13,代码来源:AddinAuthoringService.cs

示例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;
        }
开发者ID:skyronic,项目名称:TFAddin,代码行数:20,代码来源:Util.cs

示例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);
			}
		}
开发者ID:head-thrash,项目名称:monodevelop,代码行数:16,代码来源:TaskService.cs

示例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 ();
				}
			}
		}
开发者ID:vac0,项目名称:monodevelop,代码行数:13,代码来源:VersionControlService.cs

示例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 ();
			}
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:16,代码来源:MD1FileFormat.cs

示例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 ();
			}
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:32,代码来源:MD1FileFormat.cs

示例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 ();
			}
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:17,代码来源:MD1FileFormat.cs

示例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;
		}
开发者ID:sushihangover,项目名称:monodevelop,代码行数:12,代码来源:MakefileData.cs

示例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);
			}
		}
开发者ID:zenek-y,项目名称:monodevelop,代码行数:9,代码来源:InstrumentationViewerDialog.cs

示例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);
			}
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:17,代码来源:SystemAssemblyService.cs

示例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);
     }
 }
开发者ID:Kalnor,项目名称:monodevelop,代码行数:12,代码来源:ExecutionModeCommandService.cs

示例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));
				}
			}
		}
开发者ID:kthguru,项目名称:monodevelop,代码行数:10,代码来源:VersionControlService.cs


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