serialization

Serialize/Deserialize derived class as base class

自作多情 提交于 2019-12-25 09:48:07
问题 For example I have the following classes: public abstract class Device { } public class WindowsDevice: Device { } public class AndroidDevice: Device { } Now I want to serialize/deserialize WindowsDevice and AndroidDevice as XML: public static string Serialize(object o, Type[] additionalTypes = null) { var serializer = new XmlSerializer(o.GetType(), additionalTypes); using (var stringWriter = new StringWriterWithEncoding(Encoding.UTF8)) { serializer.Serialize(stringWriter, o); return

Serialize/Deserialize derived class as base class

不羁岁月 提交于 2019-12-25 09:48:02
问题 For example I have the following classes: public abstract class Device { } public class WindowsDevice: Device { } public class AndroidDevice: Device { } Now I want to serialize/deserialize WindowsDevice and AndroidDevice as XML: public static string Serialize(object o, Type[] additionalTypes = null) { var serializer = new XmlSerializer(o.GetType(), additionalTypes); using (var stringWriter = new StringWriterWithEncoding(Encoding.UTF8)) { serializer.Serialize(stringWriter, o); return

How should I serialize some simple auditing data for storing in a SQL table?

梦想与她 提交于 2019-12-25 09:18:19
问题 I have an audit table in SQL server. It is to record an entry for each high-level user action, e.g. update a record, add a new record, delete a record etc. I have a mechanism for detecting and recording all the changes made (in .NET, not as a trigger in the database) and have a collection of objects that record a field name, previous value and new value. I'm wanting to store the field changes in the same table (not in a separate table, i.e. I don't want a full-blown normalised relational

HTML input - getting the value via innerHTML or XMLSerializer

佐手、 提交于 2019-12-25 09:15:04
问题 I have an input box on a html page. I know I can get just the value, but I want the entire input string, i.e. , but with the value present: <input id="myInput" value="my entry that I just typed in"/> I have tried innerHTML, I have tried XMLSerializer, etc. var htmlDiv = document.getElementById('myInput'); var str = s.serializeToString(htmlDiv); The value is always empty. If you are wondering why I want to do this - it is because this is my simple example of what in reality is about 60 inputs,

StackOverflowException serializing STE EF object graph

白昼怎懂夜的黑 提交于 2019-12-25 08:55:59
问题 We have a .NET 4, WPF, WCF, EF 4, SQL 2008 application. One of our EF models is highly relational and in the case I'm describing could and probably does contain cycles. I've been asked to troubleshoot a case in the field where all of a sudden data from this STE EF model quit showing up in the WPF client. Upon closer examination, I found that the IIS W3WP process crashes when trying to retrieve (serialize) the STE EF object graph. I used Debug Diagnostics to capture the crash. When I looked at

Read list of lists of tuples in Python from file

夙愿已清 提交于 2019-12-25 08:49:59
问题 I'd like to read and write a list of lists of tuples from and to files. g_faces = [[(3,2)(3,5)],[(2,4)(1,3)(1,3)],[(1,2),(3,4),(6,7)]] I used pickle.dump(g_faces, fp) pickle.load(fp) But the file is not human readable. Is there an easy way to do it? 回答1: Try the json module. import json g_faces = [[(3,2), (3,5)],[(2,4), (1,3), (1,3)],[(1,2), (3,4), (6,7)]] json.dump(g_faces, open('test.json', 'w')) g_faces = json.load(open('test.json')) # cast back to tuples g_faces = [[tuple(l) for l in L]

Object deserialization failure in ojdbc14 to ojdbc6 upgrade

*爱你&永不变心* 提交于 2019-12-25 08:49:38
问题 Object deserialization is failing for BLOB datatype in our application, after upgrading jdbc driver for Oracle database. In our application, we have been using the ojdbc14 for the last couple of years without any issues. However recently we have decided to upgrde it to the ojdbc6. After upgrading to this new version, we are getting the below mentioned error, when ever we try to read(deserialize) BLOB objects from the database. These objects were serialized and saved in the databse with the

Custom DataContractSerializer

别来无恙 提交于 2019-12-25 08:38:52
问题 I want to serialize an object with DataMember attribute to be ignored on some properties. Say I have custom attribute MyIgnoreDataMember. I want properties marked with it to be invisible for my custom DataContractSerializer, but visible for the normal DataContractSerializer. And I have to use DataContractSerializer and nothing else. The code is a Silverlight app. Anyone have done subclassing DataContractSerializer successfully? 回答1: An answer to your question is complicated by the following

How to serialize an included object/property as a root?

回眸只為那壹抹淺笑 提交于 2019-12-25 08:28:04
问题 I've got a tough problem. Let's say I have a class named ObjectHost , containing a property of type BusinessObject , which itself contains some properties (let's say a Name and a Town as strings). The code would be : public class ObjectHost { public BusinessObject Data { get; set; } public ObjectHost() { Data = null; } public ObjectHost(BusinessObject ei) { Data = ei; } public override string ToString() { return (Data == null) ? "null" : Data.ToString(); } } When serializing, it will produce

Serialize arithmetic expression-tree

泪湿孤枕 提交于 2019-12-25 08:17:06
问题 I'm doing a simple task for investigation purposes. The problem is as follows: Create an arithmetic expression with variables. Build an AST for the expression. Send it to the server (using Sockets) Calculate an result of the server side and return the results. Now I can to build a tree. This method doing it: private readonly Stack<Expression> expressionStack = new Stack<Expression>(); private readonly Stack<Symbol> operatorStack = new Stack<Symbol>(); private readonly List<string> parameters