datacontractserializer

Howto ignore unknown types with DataContractSerializer

微笑、不失礼 提交于 2021-02-19 03:12:44
问题 I try to use DataContractSerializer in my application in order to be backward and forward compatible and to support round trip (if possible). Is it possible to support round trip, or if not, is it possible to just ignore unknown types in the following scenario? Suppose I have a class ClassWithObject that has a property of type object and the older version of my application stored an object of type CurrentAdditionalData in this property. [DataContract] [KnownType(typeof(CurrentAdditionalData))

Howto ignore unknown types with DataContractSerializer

烂漫一生 提交于 2021-02-19 03:08:07
问题 I try to use DataContractSerializer in my application in order to be backward and forward compatible and to support round trip (if possible). Is it possible to support round trip, or if not, is it possible to just ignore unknown types in the following scenario? Suppose I have a class ClassWithObject that has a property of type object and the older version of my application stored an object of type CurrentAdditionalData in this property. [DataContract] [KnownType(typeof(CurrentAdditionalData))

Can I configure the DataContractSerializer to not create optional (i.e. Nullable<> and List<>) elements in output XML?

大憨熊 提交于 2021-02-17 21:41:07
问题 I am using the new .NET 3.0 DataContractSerializer. I have both Nullable< > and List< > objects I am going to serialize. Example: [DataContract(Namespace = "")] class Test { public static void Go() { Test test = new Test(); var dcs = new DataContractSerializer(typeof(Test)); dcs.WriteObject(new StreamWriter("test.xml").BaseStream, test); } [DataMember] public Nullable<int> NullableNumber = null; [DataMember] public int Number = 5; [DataMember] public List<int> Numbers = new List<int>(); }

Can I configure the DataContractSerializer to not create optional (i.e. Nullable<> and List<>) elements in output XML?

拜拜、爱过 提交于 2021-02-17 21:39:54
问题 I am using the new .NET 3.0 DataContractSerializer. I have both Nullable< > and List< > objects I am going to serialize. Example: [DataContract(Namespace = "")] class Test { public static void Go() { Test test = new Test(); var dcs = new DataContractSerializer(typeof(Test)); dcs.WriteObject(new StreamWriter("test.xml").BaseStream, test); } [DataMember] public Nullable<int> NullableNumber = null; [DataMember] public int Number = 5; [DataMember] public List<int> Numbers = new List<int>(); }

need to have child by using DataContractSerializer to populate XML

☆樱花仙子☆ 提交于 2021-02-10 19:46:50
问题 I have a method that put the error messages in 1 xml and send it to client. In case of error, errors can be several, I am returning the list pf errors that are in XMLErrMessage. I want to show them in comment but each error as 1 xml child: <comments> <comment>XMLErrMessage1</comment> <comment>XMLErrMessage2</comment> <comment>XMLErrMessage3</comment> </comments> this is my method: public string ProcessXML(CommonLibrary.Model.TransferData dto, bool Authenticated) { DataContractSerializer dcs =

Custom Element Names using the DataContractSerializer on a List of primitives

こ雲淡風輕ζ 提交于 2021-02-04 14:52:07
问题 I'm interested about the best way to go about setting custom element names when using List of primitives with the DataContractSerializer. Let's say I have the following class which contains a List of Strings as a DataMember. [DataContract] public class ClassName { [DataMember] public List<String> FieldName { get; set; } } By default, this serializes to the following: <ClassName xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <FieldName xmlns:a="http://schemas.microsoft.com/2003/10

CollectionDataContract serialization not adding custom properties (DataMember)

冷暖自知 提交于 2021-01-29 02:54:31
问题 We have a legacy system that needs to be fed (XML) data in a most unstructured format. Is the following even possible with the .NET DataContractSerializer ? Given the following DataContracts [CollectionDataContract(Name = "Options", ItemName = "Option")] public class OptionItemCollection : List<OptionItem> { [DataMember(Name = "Name")] public string Name { get; set; } public OptionItemCollection() { } public OptionItemCollection(IEnumerable<OptionItem> items) : base(items) { } } [DataContract

DataContractSerializerSettings Class Examples

痴心易碎 提交于 2021-01-28 05:30:27
问题 I am looking for example on how to use the DataContractSerializerSettings class. There are two specific properties I am interested in RootName RootNameSpace. Can I use them in my code to set the namespace in the output xml? 回答1: If you're creating the DataContractSerializer , then yes. You can create a DataContractSerializerSettings object and set the RootName and/or RootNamespace using an XmlDictionary to create the XmlDictionaryString s. Here's an example: var settings = new

Predefine XML namespaces for DataContractSerializer

此生再无相见时 提交于 2020-12-25 00:02:57
问题 I'm building a self hosted WCF service. I'm building a special data structure for a very flexible transport of data. So far I test if my structure is serializable using the DataContractSerializer. That works fine and I'm happy about that, but there is something annoying me: In my XML output are dozens redefined xmlns attributes e.g.: xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:b="http://www.w3.org/2001/XMLSchema" This should be better defined once in the root

Predefine XML namespaces for DataContractSerializer

試著忘記壹切 提交于 2020-12-24 23:56:07
问题 I'm building a self hosted WCF service. I'm building a special data structure for a very flexible transport of data. So far I test if my structure is serializable using the DataContractSerializer. That works fine and I'm happy about that, but there is something annoying me: In my XML output are dozens redefined xmlns attributes e.g.: xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:b="http://www.w3.org/2001/XMLSchema" This should be better defined once in the root