datacontract

Namespace for [DataContract]

眉间皱痕 提交于 2019-11-27 06:05:42
I can't find the namespace to use for [DataContract] and [DataMember] elements. According to what I've found, it seems that adding the following should be enough, but in my case it is not. using System; using System.Runtime.Serialization; Here is a snippet of my code: using System; using System.Runtime.Serialization; namespace MyNamespace { [DataContract] public class Tuple<T1, T2> { // A custom implementation of a Tuple //... //... } } And the error I get: The type or namespace name 'DataContract' could not be found (are you missing a using directive or an assembly reference?) Am I not using

Portable class library: recommended replacement for [Serializable]

青春壹個敷衍的年華 提交于 2019-11-27 05:21:26
问题 I am porting a .NET Framework C# class library to a Portable Class Library. One recurring problem is how to deal with classes decorated with the [Serializable] attribute, since this attribute is not part of the Portable Class Library subset. Serialization functionality in the Portable Class Library subset instead appears to be covered by DataContractAttribute. To preserve as much of functionality as possible in the Portable Class Library, is it sufficient to replace [Serializable] with the

WCF: Exposing readonly DataMember properties without set?

拈花ヽ惹草 提交于 2019-11-27 00:36:16
I have a server side class which I make available on the client side through a [DataContract]. This class has a readonly field which I'd like to make available through a property. However, I'm unable to do so because it doesn't seem that I'm allowed to add a [DataMember] property without having both get and set. So - is there a way to have a [DataMember] property without setter? [DataContract] class SomeClass { private readonly int _id; public SomeClass() { .. } [DataMember] public int Id { get { return _id; } } [DataMember] public string SomeString { get; set; } } Or will the solution be use

Generate DataContract from XSD

浪尽此生 提交于 2019-11-27 00:17:38
问题 I want to be able to generate a DataContract from a XSD file, preferably using the xsd.exe tool. What is the easiest way for it to auto generate the [DataContract] and [DataMember] on each of my items? Or is there a better approach? I am trying to avoid having to recreate the data contract each time the XSD file is changed and regenerated. 回答1: The xsd.exe tool predates WCF and doesn't know anything about [DataContract] and [DataMember] . If you do use xsd.exe , you'll have to switch WCF to

WCF: Exposing readonly DataMember properties without set?

假装没事ソ 提交于 2019-11-26 22:13:42
问题 I have a server side class which I make available on the client side through a [DataContract]. This class has a readonly field which I'd like to make available through a property. However, I'm unable to do so because it doesn't seem that I'm allowed to add a [DataMember] property without having both get and set. So - is there a way to have a [DataMember] property without setter? [DataContract] class SomeClass { private readonly int _id; public SomeClass() { .. } [DataMember] public int Id {

Deserializing an IEnumerable<T> with [DataContract] applied does not work

大兔子大兔子 提交于 2019-11-26 22:07:02
问题 Rather new to Json.net and tried the following simple example serializing and then deserialing an object getting the error below: using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Collections; namespace Timehunter.Base.ServicesTests { /// <summary> /// Summary description for JsonError /// </summary> [TestClass] public class JsonError

IsReference property in data contract

心不动则不痛 提交于 2019-11-26 20:34:10
问题 What is the purpose of IsReference property in DataContract ? How does the request and response vary with this property applied? 回答1: It determines how objects are serialized, by default, IsReference=false . Setting IsReference = true allows the serialization of trees of objects that can reference each other. So with a list of Employees that each have a property for Manager (who is also an Employee ), a reference to the Manager for each Employee can be held rather than embedding the Manager

How to use Custom Serialization or Deserialization in WCF to force a new instance on every property of a datacontact ?

断了今生、忘了曾经 提交于 2019-11-26 14:23:59
问题 I have a datacontact with many members that has a custom class I would like to force a new instance if the property is null on deserialization. is there a way to do that? 回答1: If your are using DataContract serialization then you can override its default behaviour using the OnDeserialized attribute. From MSDN: When applied to a method, specifies that the method is called during deserialization of an object in an object graph. The order of deserialization relative to other objects in the graph

Namespace for [DataContract]

≯℡__Kan透↙ 提交于 2019-11-26 11:53:56
问题 I can\'t find the namespace to use for [DataContract] and [DataMember] elements. According to what I\'ve found, it seems that adding the following should be enough, but in my case it is not. using System; using System.Runtime.Serialization; Here is a snippet of my code: using System; using System.Runtime.Serialization; namespace MyNamespace { [DataContract] public class Tuple<T1, T2> { // A custom implementation of a Tuple //... //... } } And the error I get: The type or namespace name \

Configure JSON.NET to ignore DataContract/DataMember attributes

六月ゝ 毕业季﹏ 提交于 2019-11-26 06:43:20
问题 We are running into a situation on an MVC3 project with both the Microsoft JSON serializers and JSON.NET. Everybody knows DateTime\'s are basically broken in Microsoft\'s serializers, so we switched to JSON.NET to avoid this issue. That works great, except that some of the classes we are trying to serialize are POCOs with DataContract/DataMember attributes. They are defined in an assembly that is referenced in multiple places. Additionally, they have some other display properties that are not