当前位置:网站首页>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边栏推荐
- batchnorm.py这个文件单GPU运行报错解决
- Analysis and comparison of leetcode weekly race + acwing weekly race (t4/t3)
- Chia Tai International Futures: what is the master account and how to open it?
- Pandora IOT development board learning (RT thread) - Experiment 4 buzzer + motor experiment [key external interrupt] (learning notes)
- Wechat applet: the latest WordPress black gold wallpaper wechat applet two open repair version source code download support traffic main revenue
- SAP ui5 application development tutorial 107 - trial version of SAP ui5 overflow toolbar container control introduction
- 【海浪建模2】三维海浪建模以及海浪发电机建模matlab仿真
- Delaying wages to force people to leave, and the layoffs of small Internet companies are a little too much!
- Call Huawei order service to verify the purchase token interface and return connection reset
- 实战模拟│JWT 登录认证
猜你喜欢
实战模拟│JWT 登录认证
Database performance optimization tool
Logstash、Fluentd、Fluent Bit、Vector? How to choose the appropriate open source log collector
MATLB|多微电网及分布式能源交易
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
A simple SSO unified login design
[CTF] AWDP summary (WEB)
[wave modeling 2] three dimensional wave modeling and wave generator modeling matlab simulation
Basic operation of database and table ----- the concept of index
Wechat applet: the latest WordPress black gold wallpaper wechat applet two open repair version source code download support traffic main revenue
随机推荐
[pure tone hearing test] pure tone hearing test system based on MATLAB
视频网站手绘
微信小程序:星宿UI V1.5 wordpress系统资讯资源博客下载小程序微信QQ双端源码支持wordpress二级分类 加载动画优化
Redis master-slave replication cluster and recovery ideas for abnormal data loss # yyds dry goods inventory #
整理混乱的头文件,我用include what you use
Introduction to redis (1)
Package What is the function of JSON file? What do the inside ^ angle brackets and ~ tilde mean?
流批一体在京东的探索与实践
Heartless sword English translation of Xi Murong's youth without complaint
I was beaten by the interviewer because I didn't understand the sorting
Main window in QT application
增量备份 ?db full
无心剑英译席慕容《无怨的青春》
Async/await you can use it, but do you know how to deal with errors?
Playwright recording
Database postragesql lock management
微信小程序;胡言乱语生成器
If the consumer Internet is compared to a "Lake", the industrial Internet is a vast "ocean"
Wechat applet: Xingxiu UI v1.5 WordPress system information resources blog download applet wechat QQ dual end source code support WordPress secondary classification loading animation optimization
DOM basic syntax