datamember

Data member default values, how to figure out whether something was really sent?

情到浓时终转凉″ 提交于 2019-12-19 10:23:41
问题 By default, WCF deserializes missing elements into default values like null, 0 or false. The problem with this approach is that if it's a basic type like number 0 I'm not sure whether it means the real value sent by an external system or a default value generated by WCF. So my question is: Is it possible to find out at run-time whether the default value means "I didn't send anything". This is crucial because we can't update and overwrite existing data in the database with the default values

How to set [DataMember] on all class members

馋奶兔 提交于 2019-12-12 13:24:20
问题 I have a class with countless members. I want to use DataContract serialization/deserialization and so the class has the [DataContract] attribute. If I put the [DataMember] attribute that works otherwise it doesn't. Am I to put [DataMember] on all of them? Isn't there a way to automatically set ALL of them as datamembers? Thanks --EDIT-- The solution in Set DataContract and DataMember Without All the Attributes is not working. public Test() { if (false) { MyClass theclass = new MyClass(); var

C# DataMember Serializer Ordering Opposite of Expected

三世轮回 提交于 2019-12-12 04:58:56
问题 According to this article, I'd expect to see the fields in my base class at the top of the list of fields when serializing to JSON. However, I'm seeing the fields at the bottom of the list. The ordering is correct within the actual class itself, but not among the hierarchy. What's happening is it's ordering properly with the class, it it's doing the exact reverse of what I'd expect. I'd expect the base classes to have their fields serialized first. I don't want to use the Order=X attribute

R datamembers and Attributes

别来无恙 提交于 2019-12-11 04:19:56
问题 I am very new to R and am not sure about the proper language when referring to datamembers and attributes of an object. I have an object-oriented programming language background in Java so I am probably referring to datamembers/attributes in a Java set of mind. Anyway, suppose I have a matrix matClust1 and I have done the following: ids = vector() for(i in 1:size) #size is the number of rows in matClust1 { ids = c(ids, "exp") } attr(matClust1, "clustID") <- ids I think of the above as setting

DataContractSerializer to deserialize a Member without namespace?

会有一股神秘感。 提交于 2019-12-11 02:17:16
问题 I need to deserialize this xml (that I can't change): <foo:a xmlns:foo="http://example.com"> <b>string</b> </foo:a> I made this class: [DataContract(Name = "a", Namespace = "http://example.com")] public class A { [DataMember(Name = "b", Order = 0)] public string B; } And I did: using (var streamObject = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { var ser = new DataContractSerializer(typeof(A)); return (A)ser.ReadObject(streamObject); } I get an object of class A, but the content of B is

Generating class datamembers from a Vector

£可爱£侵袭症+ 提交于 2019-12-10 18:54:05
问题 Please consider this C++ question: #include <cstdio> #include <iostream> #include <vector> using namespace std; class ParseURL{ private: int qualify; // 0 means we qualify public: string node; string service; bool primary; bool health; string epoch; // methods ParseURL(string URL); ~ParseURL(); }; ParseURL::ParseURL(string URL){ vector<string> g2 = {"node", "service", "primary", "health", "epoch"}; for (string tag : g2){ auto found = URL.find(tag); if ( found != string::npos ){ auto cut_from

Compile-time re-arrangement of data members?

扶醉桌前 提交于 2019-12-10 13:25:14
问题 I was wondering about a possible way to make memory layout of a class to be more effective in templated code. As far as I know, Standard mandates data members of a class to be laid out in memory on order of their declaration. There might be possible padding done by the compiler to align the data members adding unnecessarily to the size of the class. The idea is to re-arrange data members declarations at compile time to minimize such padding. I did some searching, but couldn't find any info

Sending a Tuple object over WCF?

天大地大妈咪最大 提交于 2019-12-10 12:30:49
问题 Is the System.Tuple class supported by WCF's Data Contract Serializer (i.e., can I pass Tuple objects to WCF calls and/or receive them as part or all of the result)? I found this page, but not the clear, definitive "you can send and receive Tuples with WCF" answer I was hoping for. I'm guessing that you can, as long as all of the types within the Tuple itself are supported by the Data Contract Serializer -- can anyone provide me with a more definitive answer? Thanks. 回答1: The Tuple types are

WCF web service Data Members defaulting to null

ぐ巨炮叔叔 提交于 2019-12-09 23:14:36
问题 I am new to WCF and created a simple REST service to accept an order object (series of strings from XML file), insert that data into a database, and then return an order object that contains the results. To test the service I created a small web project and send over a stream created from an xml doc. The problem is that even though all of the items in the xml doc get placed into the stream, the service is nullifying some of them when it receives the data. For example lineItemId will have a

Can I prevent a specific datamember from being deserialized?

元气小坏坏 提交于 2019-12-07 04:22:59
问题 I have a datacontract like this [DataContract] class MyDC { [DataMember] public string DM1; [DataMember] public string DM2; [DataMember] public string DM3; } and sometimes I want to prevent DM2 from being deserialized when being returned from an OperationContract. Something like this: [OperationContact] public MyDC GetMyDC() { MyDC mdc = new MyDC(); if (condition) { // Code to prevent DM2 from being deserialized } return mdc; } I could always make a new DataContract that has only DM1 and DM3