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


C# Serialization.NetDataContractSerializer类代码示例

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


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

示例1: XmlObjectSerializerContext

 internal XmlObjectSerializerContext(NetDataContractSerializer serializer)
     : this(serializer,
     serializer.MaxItemsInObjectGraph,
     serializer.Context,
     serializer.IgnoreExtensionDataObject)
 {
 }
开发者ID:yangjunhua,项目名称:mono,代码行数:7,代码来源:XmlObjectSerializerContext.cs

示例2: LoadInstanceDataFromFile

        //Reads data from xml file and creates a dictionary based off of that.
        static IDictionary<XName, InstanceValue> LoadInstanceDataFromFile(Stream inputStream)
        {
            IDictionary<XName, InstanceValue> data = new Dictionary<XName, InstanceValue>();

            var serializer = new NetDataContractSerializer();

            using (var xmlReader = XmlReader.Create(inputStream))
            {
                var doc = new XmlDocument();
                doc.Load(xmlReader);

                var instances = doc.GetElementsByTagName("InstanceValue");
                foreach (XmlElement instanceElement in instances)
                {
                    var keyElement = (XmlElement)instanceElement.SelectSingleNode("descendant::key");
                    var key = (XName)DeserializeObject(serializer, keyElement);

                    var valueElement = (XmlElement)instanceElement.SelectSingleNode("descendant::value");
                    var value = DeserializeObject(serializer, valueElement);
                    var instVal = new InstanceValue(value);

                    data.Add(key, instVal);
                }
            }

            return data;
        }
开发者ID:bejubi,项目名称:MmapMan,代码行数:28,代码来源:XmlWorkflowInstanceStore.cs

示例3: DeserializeObject

		protected override object DeserializeObject(ArraySegment<byte> value)
		{
			var ds = new NetDataContractSerializer();

			using (var ms = new MemoryStream(value.Array, value.Offset, value.Count))
				return ds.Deserialize(ms);
		}
开发者ID:javithalion,项目名称:NCache,代码行数:7,代码来源:DataContractTranscoder.cs

示例4: SaveAllInstanceData

        /// <summary>
        /// Saves all instance data.
        /// </summary>
        /// <param name="instanceId">The instance id.</param>
        /// <param name="command">The command.</param>
        /// <returns></returns>
        /// <exception cref="System.Runtime.DurableInstancing.InstancePersistenceException"></exception>
        public Boolean SaveAllInstanceData(Guid instanceId, SaveWorkflowCommand command)
        {
            Boolean isExistingInstance;
            try
            {
                String fileName = String.Format("{0}.xml", instanceId);
                String fullPath = Path.Combine(_dataDirectory, fileName);
                isExistingInstance = File.Exists(fullPath);

                XElement root = new XElement("Instance");
                root.Add(new XAttribute("WorkflowInstanceId", instanceId));
                XDocument xml = new XDocument(root);

                NetDataContractSerializer serializer = new NetDataContractSerializer();

                XElement section = new XElement("InstanceData");
                root.Add(section);
                foreach(var entry in command.InstanceData)
                {
                    SaveSingleEntry(serializer, section, entry);
                }
                SaveInstanceDocument(fullPath, xml);
            }
            catch(Exception exception)
            {
                Dev2Logger.Log.Error(exception);
                throw new InstancePersistenceException(exception.Message, exception);
            }
            return isExistingInstance;
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:37,代码来源:FileSystemInstanceStoreIO.cs

示例5: Deserialize

 public override object Deserialize(Type type, byte[] data)
 {
     var formatter = new NetDataContractSerializer();
     using (var ms = new MemoryStream(data))
     {
         return formatter.Deserialize(ms);
     }
 }
开发者ID:danni95,项目名称:Core,代码行数:8,代码来源:NetDataContractSerializationProvider.cs

示例6: DeserializeGraph

 // Deserializes a stream to a graph using the NetDataContractSerializer (binary mode)
 private static object DeserializeGraph(Stream rawBytes)
 {
     using (XmlDictionaryReader dr = XmlDictionaryReader.CreateBinaryReader(rawBytes, XmlDictionaryReaderQuotas.Max))
     {
         object deserialized = new NetDataContractSerializer().ReadObject(dr);
         return deserialized;
     }
 }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:9,代码来源:MvcSerializer.cs

示例7: XmlObjectSerializerReadContextComplex

 internal XmlObjectSerializerReadContextComplex(NetDataContractSerializer serializer) : base(serializer)
 {
     this.mode = SerializationMode.SharedType;
     this.preserveObjectReferences = true;
     this.binder = serializer.Binder;
     this.surrogateSelector = serializer.SurrogateSelector;
     this.assemblyFormat = serializer.AssemblyFormat;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:XmlObjectSerializerReadContextComplex.cs

示例8: BinaryStateSerializer

        public BinaryStateSerializer(ILogger logger)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");

            this.logger = logger;
            netDataContractSerializer = new NetDataContractSerializer();
            load();
        }
开发者ID:sat-dev,项目名称:MySamples,代码行数:9,代码来源:BinaryStateSerializer.cs

示例9: Serialize

 public override byte[] Serialize(object obj)
 {
     var formatter = new NetDataContractSerializer();
     using (var ms = new MemoryStream())
     {
         formatter.Serialize(ms, obj);
         return ms.ToArray();
     }
 }
开发者ID:danni95,项目名称:Core,代码行数:9,代码来源:NetDataContractSerializationProvider.cs

示例10: 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

示例11: Deserialize

 public static object Deserialize(byte[] buffer)
 {
     using (MemoryStream memStream = new MemoryStream(buffer))
     using (GZipStream zipStream = new GZipStream(memStream, CompressionMode.Decompress))
     using (XmlDictionaryReader xmlDictionaryReader = XmlDictionaryReader.CreateBinaryReader(zipStream, XmlDictionaryReaderQuotas.Max))
     {
         NetDataContractSerializer serializer = new NetDataContractSerializer();
         return serializer.ReadObject(xmlDictionaryReader);
     }
 }
开发者ID:lmagyar,项目名称:Orleans.Activities,代码行数:10,代码来源:InstanceValueDictionarySerializer.cs

示例12: Clone

 /// <summary>
 /// Creates a new instance of the class with the same value as instance.
 /// </summary>
 /// <returns>Returns cloned object.</returns>
 public virtual object Clone()
 {
     IFormatter formatter = new NetDataContractSerializer();
     using(Stream stream = new MemoryStream())
     {
         formatter.Serialize(stream, this);
         stream.Seek(0, SeekOrigin.Begin);
         return formatter.Deserialize(stream);
     }
 }
开发者ID:onesimoh,项目名称:Andamio,代码行数:14,代码来源:EntityBase.cs

示例13: XmlObjectSerializerWriteContextComplex

 internal XmlObjectSerializerWriteContextComplex(NetDataContractSerializer serializer, Hashtable surrogateDataContracts)
     : base(serializer)
 {
     this.mode = SerializationMode.SharedType;
     this.preserveObjectReferences = true;
     this.streamingContext = serializer.Context;
     this.binder = serializer.Binder;
     this.surrogateSelector = serializer.SurrogateSelector;
     this.surrogateDataContracts = surrogateDataContracts;
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:10,代码来源:XmlObjectSerializerWriteContextComplex.cs

示例14: Deserialize

        private object Deserialize(string value, Type type)
        {
            using (var m = new MemoryStream(Encoding.Unicode.GetBytes(value)))
            {
                var r = XmlDictionaryReader.CreateTextReader(m, Encoding.Unicode, XmlDictionaryReaderQuotas.Max, null);

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

                return s.ReadObject(r);
            }
        }
开发者ID:skyquery,项目名称:graywulf,代码行数:12,代码来源:PluginDataContractResolverTest.cs

示例15: Main

        static void Main(string[] args)
        {
            var ns = new NetDataContractSerializer();
            // NetDataContractSerializer is otherwise the same to use
            // as DataContractSerializer.
            Person p = new Person { Name = "Stacey", Age = 30 };
            var ds = new DataContractSerializer(typeof(Person));
            XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
            using (XmlWriter w = XmlWriter.Create("person.xml", settings))
                ds.WriteObject(w, p);

            System.Diagnostics.Process.Start("person.xml");
        }
开发者ID:ErhanGDC,项目名称:MyWorks,代码行数:13,代码来源:Program.cs


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