当前位置:网站首页>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边栏推荐
- [pure tone hearing test] pure tone hearing test system based on MATLAB
- 增量备份 ?db full
- batchnorm.py这个文件单GPU运行报错解决
- 当产业互联网时代真正发展完善之后,将会在每一个场景见证巨头的诞生
- 微信小程序:星宿UI V1.5 wordpress系统资讯资源博客下载小程序微信QQ双端源码支持wordpress二级分类 加载动画优化
- Classification of performance tests (learning summary)
- LeetCode周赛 + AcWing周赛(T4/T3)分析对比
- Game 280 of leetcode week
- MySQL REGEXP:正则表达式查询
- Analysis and comparison of leetcode weekly race + acwing weekly race (t4/t3)
猜你喜欢
微信小程序:星宿UI V1.5 wordpress系统资讯资源博客下载小程序微信QQ双端源码支持wordpress二级分类 加载动画优化
Wechat applet; Gibberish generator
Pandora IOT development board learning (RT thread) - Experiment 4 buzzer + motor experiment [key external interrupt] (learning notes)
资深测试/开发程序员写下无bug?资历(枷锁)不要惧怕错误......
Basic operation of database and table ----- the concept of index
Single step debugging of master data reading of SAP commerce cloud products
Logstash、Fluentd、Fluent Bit、Vector? How to choose the appropriate open source log collector
微信小程序:全网独家小程序版本独立微信社群人脉
Take you ten days to easily complete the go micro service series (IX. link tracking)
Blue Bridge Cup Square filling (DFS backtracking)
随机推荐
The performance of major mainstream programming languages is PK, and the results are unexpected
Are you still writing the TS type code
Phpstrom setting function annotation description
A simple SSO unified login design
Take you ten days to easily complete the go micro service series (IX. link tracking)
Database performance optimization tool
微信小程序:全新独立后台月老办事处一元交友盲盒
[development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39
流批一体在京东的探索与实践
Research Report on the overall scale, major producers, major regions, products and application segmentation of agricultural automatic steering system in the global market in 2022
Wechat applet: wechat applet source code download new community system optimized version support agent member system function super high income
增量备份 ?db full
[FPGA tutorial case 10] design and implementation of complex multiplier based on Verilog
线上故障突突突?如何紧急诊断、排查与恢复
Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and mobile phones can also easily read literature
Compare whether two lists are equal
【大型电商项目开发】性能压测-优化-中间件对性能的影响-40
Wechat applet: new independent backstage Yuelao office one yuan dating blind box
Four pits in reentrantlock!
JS implementation determines whether the point is within the polygon range