本文整理汇总了C#中System.Runtime.Serialization.NetDataContractSerializer类的典型用法代码示例。如果您正苦于以下问题:C# NetDataContractSerializer类的具体用法?C# NetDataContractSerializer怎么用?C# NetDataContractSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetDataContractSerializer类属于System.Runtime.Serialization命名空间,在下文中一共展示了NetDataContractSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: DeserializeMethodBase
static KeyValuePair<string, MethodBase> DeserializeMethodBase(XmlReader reader)
{
var sb = new StringBuilder();
sb.Append(reader.ReadOuterXml());
var s = sb.ToString();
var ndcs = new NetDataContractSerializer();
using (var sr = new StringReader(s))
using (var xr = new XmlTextReader(sr))
{
return new KeyValuePair<string, MethodBase>(s, (MethodBase)ndcs.ReadObject(xr));
}
}
开发者ID:umaranis,项目名称:Prig,代码行数:13,代码来源:StubElement.cs
示例17: SholdSerializeOperator
public void SholdSerializeOperator()
{
// Given
var entity = new FilterTestEntity { StringField = "Abc", IntField = 5 };
// Какое-то сложное логическое выражение
var specification = new FilterSpecification<FilterTestEntity>(
b => b.Or(
c => c
.And(a => a.Or(o => o
.Null(i => i.StringField)
.Equal(i => i.StringField, string.Empty))
.Equal(i => i.IntField, 0))
.And(a => a
.NotNull(i => i.StringField)
.NotEqual(i => i.StringField, string.Empty)
.Or(o => o
.In(i => i.StringField.ToLower(), new[] { "a", "b", "c" })
.Contains(i => i.StringField.ToLower(), "abc")
.StartsWith(i => i.StringField, "1")
.EndsWith(i => i.StringField, "5"))
.Or(o => o
.And(a2 => a2
.GreaterOrEqual(i => i.IntField, 0)
.LessOrEqual(i => i.IntField, 10))
.And(a2 => a2
.Greater(i => i.IntField, 10)
.Less(i => i.IntField, 20))
.Between(i => i.IntField, 20, 30)))));
IFilterOperator operatorFromStream;
IFilterOperator operatorToStream = specification.Operator;
// When
using (var stream = new MemoryStream())
{
// Сериализация
var serializer = new NetDataContractSerializer();
serializer.Serialize(stream, operatorToStream);
stream.Position = 0;
// Десериализация
operatorFromStream = (IFilterOperator)serializer.ReadObject(stream);
}
// Then
Assert.IsNotNull(operatorFromStream);
Assert.AreEqual(operatorToStream.IsSatisfiedBy(entity), operatorFromStream.IsSatisfiedBy(entity));
}
开发者ID:AlexMAS,项目名称:Specifications,代码行数:49,代码来源:FilterSpecificationTest.cs
示例18: 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
示例19: SerializingTaskTest
public async Task SerializingTaskTest()
{
var count = 10;
var action = new Action(() => count=count+5);
Assert.AreEqual(count, 10);
var sr = new NetDataContractSerializer();
//v//ar actionString = sr.S
//var actionString = JsonConvert.SerializeObject(action);
//var newAction = JsonConvert.DeserializeObject<Action>(actionString);
//newAction.Invoke();
Assert.AreEqual(count, 15);
}
开发者ID:jdhemry,项目名称:UnifiedData,代码行数:15,代码来源:VehicleContextTests.cs
示例20: 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
注:本文中的System.Runtime.Serialization.NetDataContractSerializer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论