xml-serialization

serialize list of generic type

a 夏天 提交于 2019-12-25 04:43:04
问题 I am writing an application for serialization of a generic List that holds any datatype.So I designed a base-DataType to fill the list with as follows: public abstract class GenericObject<T> { public string key; public T value; public GenericObject() { } public GenericObject(string key, T value) : this() { this.key = key; this.value = value; } } Furthermore there is a class GenericList which implements the IXmlSerializable -Interface to write a key-value pair as like this: GenericObject<int>

sgen.exe, XmlSerializers.dll not being used

坚强是说给别人听的谎言 提交于 2019-12-25 03:59:21
问题 I need to produce XML serializers for certain of my classes in advance to avoid them being built when the application runs. I managed to (eventually) get sgen running as a post build operation. It appears to be working as it produces the expected DLL. However its not being used. I have configured the diagnostics to leave the files on disk and I can see them still being produced. This is with an existing class (ClassA) of moderate complexity. So I created a simple class (ClassB) and tested on

Can't access Element after DataContractSerializer

我的未来我决定 提交于 2019-12-25 02:59:39
问题 I have a simple object I'm trying to serialize using DataContractSerializer. In my unit test, I'm trying to verify the xml contains the right value for the product/sku node. My product class: [DataContract(Namespace = "http://foo.com/catalogue/") partial class Product { [DataMember(Name = "sku")] public virtual string ProductSKU { get { return _productSKU; } set { OnProductSKUChanging(); _productSKU = value; OnProductSKUChanged(); } } } Here's the method I'm testing: public XDocument

read the data from XML Structure using c#

▼魔方 西西 提交于 2019-12-25 02:21:31
问题 I store the xml file in one string object like,I stored the xml structure in local variable string abcd in c#. <structure> <a>Test Name</a> <e>test address</e> <c> <c1>yyyy<c1> <c2>xxxx</c2> </c> </structure> How to read(parse) this xml string using c# and store the tag a,and tag c1 ,tag c2 values in local variable using c#. i tried like XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(abcd); XmlElement element = (XmlElement)xmldoc.GetElementById("a"); but i get null value.how to read

How do I change the XmlElement name dynamically?

隐身守侯 提交于 2019-12-25 01:54:08
问题 [XmlRoot("A")] public class Foos { [XmlElement("A1")] public List<Foo> FooList{ get; set; } } var serializer = new XmlSerializer(typeof(Foos)); This code working as well. But its not dynamic. I want [XmlRoot("A")] to [XmlRoot(ConfigurationManager.AppSettings[someValue])] . But is throw to syntax error. Then i try this public class Foos { [XmlElement("A1")] public List<Foo> FooList{ get; set; } } var serializer = new XmlSerializer(typeof(Foos),new XmlRootAttribute(ConfigurationManager

c# System.Xml.Serialization does not goes throught set method of Public List<T>

左心房为你撑大大i 提交于 2019-12-25 01:48:34
问题 I want to deserialize back my class using System.Xml.Serialization, but i've noticed a strange behaviour using List Properties: it never calls the set method, which lead me to loosing vital informations ... I'd like to avoid to switch serialization method. public class Category { private string _name; private List<Category> _subCategories; private Category _parent; public string Name { get { return _name; } set { _name = value; } } public List<Category> SubCategories { get { return

Error: “missing a mandatory child element”

半世苍凉 提交于 2019-12-25 00:55:18
问题 Following the steps from Lesson 5: Publish the Report Definition to the Report Server for SQL Server 2012, I have the following error: The definition of this report is not valid or supported by this version of Reporting Services. The report definition may have been created with a later version of Reporting Services, or contain content that is not well-formed or not valid based on Reporting Services schemas. Details: The report definition element 'Report' is empty at line 1878, position 3. It

Deserialize matching types from different assemblies

谁说我不能喝 提交于 2019-12-25 00:46:19
问题 If I have a class/interface pair defined in AssemblyA under namespace AssemblyA.Entities : public IEntity { string Name { get; set; } } [Serializable] public Entity : IEntity { public string Name { get; set; } } And I serialize it to XML using XmlSerializer : var myEntities = new List<IEntity>(); // myEntities is populated somehow var data = XmlSerializationManager.Serialize(myEntities); // 'data' gets saved to disk somewhere as a file Then , if I duplicate the code/namespaces into AssemblyB

Serializing class inherited from List<> using DataContractSerializer does not serialize object properties

匆匆过客 提交于 2019-12-25 00:13:03
问题 Since XmlSerializer can not serialize any other properties when the class is inherited from List <> , I try to solve them with the DataContractSerializer . This should work, as described here: When a class is inherited from List<>, XmlSerializer doesn't serialize other attributes But I get the same results. If the object is inherited from List <> the TestValue property is not serialized. using System.Runtime.Serialization; [Serializable] public class XSerBase { [DataMember] public XSerTest

Serializing / Deserializing the derived class

时间秒杀一切 提交于 2019-12-24 23:24:37
问题 I have a base class and another derived from it. Let's assume, the base class has 20 members and derived has 5 members. Only the derived class is serializable. After I instantiate, the derived class's object has all 25 members. Now how can I only serialize the 5 members of derived class? When I use "this" to serizalize or deserialize, the entire class (all 25 members) is serialized and then deserialized. Here is a code snippet (not complete): // Base class definition. public abstract class