本文整理汇总了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)
{
}
示例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;
}
示例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);
}
示例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;
}
示例5: Deserialize
public override object Deserialize(Type type, byte[] data)
{
var formatter = new NetDataContractSerializer();
using (var ms = new MemoryStream(data))
{
return formatter.Deserialize(ms);
}
}
示例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;
}
}
示例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();
}
示例9: Serialize
public override byte[] Serialize(object obj)
{
var formatter = new NetDataContractSerializer();
using (var ms = new MemoryStream())
{
formatter.Serialize(ms, obj);
return ms.ToArray();
}
}
示例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));
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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");
}