当前位置:网站首页>WCF: expose unset read-only DataMember property- WCF: Exposing readonly DataMember properties without set?
WCF: expose unset read-only DataMember property- WCF: Exposing readonly DataMember properties without set?
2022-07-05 01:29:00 【Zafo】
problem :
I have a server side class which I make available on the client side through a [DataContract]. I have a server-side class , Can pass [DataContract] Use on client .This class has a readonly field which I'd like to make available through a property. This class has a read-only field , I want to provide this field through an attribute .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. however , I can't do this , Because it seems that I am not allowed to get and set Add if [DataMember] attribute .
So - is there a way to have a [DataMember] property without setter? therefore - Is there any way? No setter Of [DataMember] Attribute ?
[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 the [DataMember] as the field - (like eg shown here )? Or use it in the solution [ Data member ] As field - ( For example, image display ad locum )?Tried doing this too, but it doesn't seem to care the field is readonly..? I have also tried to do this , But it doesn't seem to care that the field is read-only .
Edit : Is the only way to make a readonly property by hacking it like this? edit : Is this the only way to make it a read-only property ?(no - I don't want to do this...)( no - I don't want to do that ...)
[DataMember]public int Id{ get { return _id; } private set { /* NOOP */ }}Solution :
Reference resources : https://stackoom.com/en/question/7rRd边栏推荐
- Pandora IOT development board learning (RT thread) - Experiment 4 buzzer + motor experiment [key external interrupt] (learning notes)
- 【CTF】AWDP总结(Web)
- Are you still writing the TS type code
- Using openpyxl module to write the binary list into excel file
- Exploration and practice of integration of streaming and wholesale in jd.com
- I was beaten by the interviewer because I didn't understand the sorting
- 增量备份 ?db full
- JS implementation determines whether the point is within the polygon range
- Jcenter () cannot find Alibaba cloud proxy address
- PHP 基础篇 - PHP 中 DES 加解密详解
猜你喜欢

To sort out messy header files, I use include what you use

Exploration and practice of integration of streaming and wholesale in jd.com

Single step debugging of master data reading of SAP commerce cloud products

Blue Bridge Cup Square filling (DFS backtracking)
![Grabbing and sorting out external articles -- status bar [4]](/img/88/8267ab92177788ac17ab665a90b781.png)
Grabbing and sorting out external articles -- status bar [4]

Actual combat simulation │ JWT login authentication

A simple SSO unified login design

流批一体在京东的探索与实践

【大型电商项目开发】性能压测-优化-中间件对性能的影响-40

Roads and routes -- dfs+topsort+dijkstra+ mapping
随机推荐
Main window in QT application
I was beaten by the interviewer because I didn't understand the sorting
Can financial products be redeemed in advance?
If the consumer Internet is compared to a "Lake", the industrial Internet is a vast "ocean"
Four pits in reentrantlock!
Incremental backup? db full
【LeetCode】88. Merge two ordered arrays
To sort out messy header files, I use include what you use
线上故障突突突?如何紧急诊断、排查与恢复
LeetCode周赛 + AcWing周赛(T4/T3)分析对比
MySQL regexp: Regular Expression Query
Armv8-a programming guide MMU (3)
Package What is the function of JSON file? What do the inside ^ angle brackets and ~ tilde mean?
C语音常用的位运算技巧
微信小程序:全新独立后台月老办事处一元交友盲盒
Database postragesq PAM authentication
微信小程序:全网独家小程序版本独立微信社群人脉
微信小程序:独立后台带分销功能月老办事处交友盲盒
Robley's global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
增量备份 ?db full