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


C# NetDataContractSerializer.WriteObject方法代码示例

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


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

示例1: ToElement

			public XElement ToElement(object val, Func<Type, XNamespace> getNamespace)
			{
				var serializer = new NetDataContractSerializer();
				using (var ms = new MemoryStream())
				{
					serializer.WriteObject(ms, val);
					ms.Seek(0, SeekOrigin.Begin);
					return XElement.Load(new XmlTextReader(ms));
				}
			}
开发者ID:BiYiTuan,项目名称:rhino-esb,代码行数:10,代码来源:When_custom_element_serialization_is_used.cs

示例2: Serialize

 public static byte[] Serialize(object graph)
 {
     using (MemoryStream memStream = new MemoryStream())
     using (GZipStream zipStream = new GZipStream(memStream, CompressionMode.Compress))
     {
         using (XmlDictionaryWriter xmlDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(zipStream))
         {
             NetDataContractSerializer serializer = new NetDataContractSerializer();
             serializer.WriteObject(xmlDictionaryWriter, graph);
             xmlDictionaryWriter.Close();
         }
         zipStream.Close();
         return memStream.ToArray();
     }
 }
开发者ID:lmagyar,项目名称:Orleans.Activities,代码行数:15,代码来源:InstanceValueDictionarySerializer.cs

示例3: Serialize

        private string Serialize(object value, Type type)
        {
            using (var m = new MemoryStream())
            {
                var w = XmlDictionaryWriter.CreateTextWriter(m, Encoding.Unicode);

                //var s = new DataContractSerializer(type, null, Int32.MaxValue, false, false, null, new PluginDataContractResolver());
                var s = new NetDataContractSerializer();

                s.WriteObject(w, value);
                w.Flush();
                w.Close();

                return System.Text.Encoding.Unicode.GetString(m.ToArray());
            }
        }
开发者ID:skyquery,项目名称:graywulf,代码行数:16,代码来源:PluginDataContractResolverTest.cs

示例4: GetSerializedVersion

 private static Response GetSerializedVersion(object response)
 {
     try
     {
         using (var stream = new MemoryStream())
         {
             var serializer = new NetDataContractSerializer();
             serializer.WriteObject(stream, response);
             stream.Position = 0;
             return (Response)serializer.ReadObject(stream);
         }
     }
     catch (Exception ex)
     {
         throw new ColomboSerializationException(string.Format("{0} could not be serialized.", response), ex);
     }
 }
开发者ID:julienblin,项目名称:Colombo,代码行数:17,代码来源:StubRequestHandleInvocation.cs

示例5: WriteCompilerOutput

 private static void WriteCompilerOutput(string path, WorkflowCompilerResults results)
 {
     using (Stream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
     {
         XmlWriterSettings settings = new XmlWriterSettings {
             Indent = true
         };
         using (XmlWriter writer = XmlWriter.Create(stream, settings))
         {
             NetDataContractSerializer serializer = new NetDataContractSerializer();
             SurrogateSelector selector = new SurrogateSelector();
             selector.AddSurrogate(typeof(MemberAttributes), serializer.Context, new CompilerResultsSurrogate());
             serializer.SurrogateSelector = selector;
             serializer.WriteObject(writer, results);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:Program.cs

示例6: Net_data_contract_serialization_will_not_change_the_type_of_a_collection

        public void Net_data_contract_serialization_will_not_change_the_type_of_a_collection()
        {
            using (var session = DataAccess.OpenSession())
            {
                var forum = session.Get<ForumModel>(1);

                //company.EmployeesList made public for the purpose of
                //this demo
                Assert.AreEqual(typeof(NHibernate.Collection.Generic.PersistentGenericBag<TopicModel>), forum.Topics.GetType());

                var serializer = new NetDataContractSerializer();

                //serialize company to a memory stream
                Stream stream = new MemoryStream();
                serializer.WriteObject(stream, forum);
                Console.WriteLine();
                //deserialize the memory stream back to a company
                stream.Position = 0;
                forum = (ForumModel)serializer.ReadObject(stream);

                Assert.AreEqual(typeof(NHibernate.Collection.Generic.PersistentGenericBag<TopicModel>), forum.Topics.GetType());
            }
        }
开发者ID:michal-franc,项目名称:ElearnServices,代码行数:23,代码来源:DataSerializationTests.cs

示例7: SerializeObject2

		internal ArraySegment<byte> SerializeObject2(object source)
		{
			ArraySegment<byte> nums = new ArraySegment<byte>(PSWorkflowFileInstanceStore.NullArray);
			try
			{
				XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
				using (MemoryStream memoryStream = new MemoryStream())
				{
					netDataContractSerializer.WriteObject(memoryStream, source);
					byte[] numArray = new byte[(IntPtr)(memoryStream.Length + (long)1)];
					numArray[0] = 70;
					Buffer.BlockCopy(memoryStream.GetBuffer(), 0, numArray, 1, (int)memoryStream.Length);
					nums = new ArraySegment<byte>(numArray, 0, (int)numArray.Length);
					memoryStream.Close();
				}
			}
			catch (SerializationException serializationException1)
			{
				SerializationException serializationException = serializationException1;
				this.ThrowErrorOrWriteWarning(serializationException);
			}
			catch (InvalidDataContractException invalidDataContractException1)
			{
				InvalidDataContractException invalidDataContractException = invalidDataContractException1;
				this.ThrowErrorOrWriteWarning(invalidDataContractException);
			}
			catch (Exception exception1)
			{
				Exception exception = exception1;
				this.Tracer.TraceException(exception);
				throw;
			}
			return nums;
		}
开发者ID:nickchal,项目名称:pash,代码行数:34,代码来源:PSWorkflowFileInstanceStore.cs

示例8: TryNetDataContractSerializer

        private bool TryNetDataContractSerializer(Type type)
        {
            using (var m = new MemoryStream())
            {
                var w = XmlTextWriter.Create(
                    m,
                    new XmlWriterSettings()
                    {
                        Indent = true,
                        Encoding = Encoding.Unicode,
                        NamespaceHandling = NamespaceHandling.OmitDuplicates,
                    });

                var s = new NetDataContractSerializer(
                    new StreamingContext(),
                    int.MaxValue,
                    false,
                    System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple,
                    null);

                var o = Activator.CreateInstance(type, true);

                s.WriteObject(w, o);
                w.Flush();
                w.Close();

                // Don't forget to skip byte order mark
                var buffer = m.ToArray();
                var prelen = Encoding.Unicode.GetPreamble().Length;
                var xml = System.Text.Encoding.Unicode.GetString(buffer, prelen, buffer.Length - prelen);
            }

            return true;
        }
开发者ID:skyquery,项目名称:graywulf,代码行数:34,代码来源:SerializableChecker.cs

示例9: SaveResultsToFile

		private static void SaveResultsToFile(ScheduledJob job, FileStream fs)
		{
			XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
			netDataContractSerializer.WriteObject(fs, job);
			fs.Flush();
		}
开发者ID:nickchal,项目名称:pash,代码行数:6,代码来源:ScheduledJobSourceAdapter.cs

示例10: SaveSchemas

        public static void SaveSchemas(string filename)
        {
            using ( FileStream fs = new FileStream(filename, FileMode.Create) )
             {
            XmlWriter xw = XmlWriter.Create(fs);
            xw.WriteStartDocument();

            xw.WriteStartElement("SchemaDefinitions");
            foreach ( var schema in schemas )
            {
               NetDataContractSerializer sr = new NetDataContractSerializer();
               sr.WriteObject(xw, schema.Value);
            }
            xw.WriteEndElement(); // SchemaDefinitions

            xw.WriteEndDocument();
            xw.Flush();
             }
        }
开发者ID:VivekRagunathan,项目名称:EI,代码行数:19,代码来源:EntitySchemaManager.cs

示例11: GetBinarySerializedForm

        byte[] GetBinarySerializedForm(object instance)
        {
            NetDataContractSerializer serializer = new NetDataContractSerializer();
            MemoryStream memStr = new MemoryStream();
            XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(memStr);

            serializer.WriteObject(dictionaryWriter, instance);
            dictionaryWriter.Flush();

            byte[] bytes = memStr.ToArray();

            dictionaryWriter.Close();
            memStr.Close();

            return bytes;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:16,代码来源:SqlPersistenceProviderFactory.cs

示例12: UpdateJobStore

		private void UpdateJobStore()
		{
			FileStream fileForJobDefinition = null;
			try
			{
				fileForJobDefinition = ScheduledJobStore.GetFileForJobDefinition(this.Name, FileMode.Create, FileAccess.Write, FileShare.None);
				XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
				netDataContractSerializer.WriteObject(fileForJobDefinition, this);
				fileForJobDefinition.Flush();
			}
			finally
			{
				if (fileForJobDefinition != null)
				{
					fileForJobDefinition.Close();
				}
			}
			if (this.Credential != null)
			{
				this.UpdateFilePermissions(this.Credential.UserName);
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:22,代码来源:ScheduledJobDefinition.cs

示例13: AddToJobStore

        /// <summary>
        /// Adds this scheduled job definition to the job definition store.
        /// </summary>
        private void AddToJobStore()
        {
            FileStream fs = null;
            try
            {
                fs = ScheduledJobStore.CreateFileForJobDefinition(Name);
                _definitionFilePath = ScheduledJobStore.GetJobDefinitionLocation();
                _definitionOutputPath = ScheduledJobStore.GetJobRunOutputDirectory(Name);

                XmlObjectSerializer serializer = new System.Runtime.Serialization.NetDataContractSerializer();
                serializer.WriteObject(fs, this);
                fs.Flush();
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }

            // If credentials are provided then update permissions.
            if (Credential != null)
            {
                UpdateFilePermissions(Credential.UserName);
            }
        }
开发者ID:dfinke,项目名称:powershell,代码行数:30,代码来源:ScheduledJobDefinition.cs

示例14: SaveResultsToFile

 /// <summary>
 /// Writes the job (which implements ISerializable) to the provided
 /// file stream.
 /// </summary>
 /// <param name="job">ScheduledJob job to save</param>
 /// <param name="fs">FileStream</param>
 private static void SaveResultsToFile(ScheduledJob job, FileStream fs)
 {
     XmlObjectSerializer serializer = new System.Runtime.Serialization.NetDataContractSerializer();
     serializer.WriteObject(fs, job);
     fs.Flush();
 }
开发者ID:40a,项目名称:PowerShell,代码行数:12,代码来源:ScheduledJobSourceAdapter.cs

示例15: Save

 /// <summary>
 /// Saves the machine to an output stream.
 /// </summary>
 /// <param name="output"></param>
 public void Save(Stream output)
 {
     NetDataContractSerializer serializer = new NetDataContractSerializer();
     serializer.WriteObject(output, this);
 }
开发者ID:EusthEnoptEron,项目名称:Sketchball,代码行数:9,代码来源:PinballMachine.cs


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