datamember

Accessing different data members belonging to the same object from 2 different thread in C++

回眸只為那壹抹淺笑 提交于 2021-02-07 07:09:05
问题 I have a few objects I need to perform actions on from different threads in c++. I known it is necessary to lock any variable that may be used by more than one thread at the same time, but what if each thread is accessing (writing to) a different data member of the same object? For example, each thread is calling a different method of the object and none of the methods called modify the same data member. Is it safe as long as I don't access the same data member or do I need to lock the whole

Accessing different data members belonging to the same object from 2 different thread in C++

自闭症网瘾萝莉.ら 提交于 2021-02-07 07:08:51
问题 I have a few objects I need to perform actions on from different threads in c++. I known it is necessary to lock any variable that may be used by more than one thread at the same time, but what if each thread is accessing (writing to) a different data member of the same object? For example, each thread is calling a different method of the object and none of the methods called modify the same data member. Is it safe as long as I don't access the same data member or do I need to lock the whole

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

What if an argument has the same name as that of a data member?

偶尔善良 提交于 2020-01-16 09:59:38
问题 #include <iostream> struct A { A(int n) { std::cout << n; } int n{2}; }; int main() { A a{1}; } The output is 1 rather than 2 . Does the C++ standard define that the argument name is preferred if it is the same as that of a data member? 回答1: The argument is in a "closer" scope than the member variable, so the argument shadows the member variable. The obvious solution is to rename the argument (or the member variable), so they are not the same anymore. You can also use this->n to explicitly

WCF An error occurred while receiving the HTTP response

▼魔方 西西 提交于 2020-01-05 12:08:59
问题 Here's what my WCF service should be returning. When I command PaymentData out of ResponseModel and add other DataMembers in that class it works. [DataContract] public class ResponseModel { [DataMember] public PaymentData PaymentData { get; set; } } Here's the PaymentData class: [DataContract] public class PaymentData { [DataMember] public PaymentType PaymentType { get; set; } [DataMember] public string CardNumber { get; set; } [DataMember] public DateTime ExpirationDate { get; set; } ///

Adding a DataMember to a different namespace to the DataContract

て烟熏妆下的殇ゞ 提交于 2020-01-02 08:26:30
问题 With the XmlSerializer I can have my members in different namespaces to the parent type. Can I do the same thing with DataContractSerializer ? I would like the following XML: <h:Type xmlns:h="http://schemas.e.com/WebServices" xmlns="http://schemas.e.com/WebServices"> <Member xmlns="http://schemas.e.com/CoreTypes">0</Member> </h:Type> Is this possible in with DataContractSerializer ? 回答1: You can define subdatacontracts in different namespaces and use them as members of another datacontract,

Adding a DataMember to a different namespace to the DataContract

自作多情 提交于 2020-01-02 08:25:41
问题 With the XmlSerializer I can have my members in different namespaces to the parent type. Can I do the same thing with DataContractSerializer ? I would like the following XML: <h:Type xmlns:h="http://schemas.e.com/WebServices" xmlns="http://schemas.e.com/WebServices"> <Member xmlns="http://schemas.e.com/CoreTypes">0</Member> </h:Type> Is this possible in with DataContractSerializer ? 回答1: You can define subdatacontracts in different namespaces and use them as members of another datacontract,

Trying to map two different types to one value

依然范特西╮ 提交于 2019-12-24 07:36:08
问题 I have a DataMember that I need to be filled in by an api json string... [DataContract] public class Values { [DataMember] public object value { get; set; } } API json string : [ { "type": "text", "values": [ { "value": "Text that is in textfield" } ] }, { "type": "category", "values": [ { "value": { "text": "Category title", "color": "#000000" } } ] } ] I map this string to a strong typed object Field like so: private List<Field> PrepFieldObject(string response) { using (MemoryStream stream

What does it mean to put DataMemberAttribute on interface member?

这一生的挚爱 提交于 2019-12-21 09:29:24
问题 What does it mean to put a DataMemberAttribute on an interface member? How does this affect derived classes? 回答1: As shown in the following signature, the DataMember attribute is not inheritable [AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, Inherited = false, AllowMultiple = false)] public sealed class DataMemberAttribute : Attribute Therefore, it makes very little sense to decorate interface members with this attribute as you will have to decorate the

DataContract, default DataMember value

自作多情 提交于 2019-12-21 06:59:44
问题 Is there a way to choose default values of attributes that are not in the xml file during deserialization? If the mAge attribute is not present in the xml file, I want to use a default value of 18. Is it possible ? [DataContract] public class Person { public Person () { } [DataMember(Name = "Name")] public string mName { get; set; } [DataMember(Name = "Age")] public int mAge { get; set; } [DataMember(Name = "Single")] public bool mIsSingle { get; set; } }; Edit to put the answer.