当前位置:网站首页>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边栏推荐
- 小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
- Intel sapphire rapids SP Zhiqiang es processor cache memory split exposure
- Check if this is null - checking if this is null
- Logstash、Fluentd、Fluent Bit、Vector? How to choose the appropriate open source log collector
- 整理混乱的头文件,我用include what you use
- Blue Bridge Cup Square filling (DFS backtracking)
- Database postragesq peer authentication
- Take you ten days to easily complete the go micro service series (IX. link tracking)
- PHP 约瑟夫环问题
- Postman automatically fills headers
猜你喜欢

Wechat applet; Gibberish generator

Wechat applet: the latest WordPress black gold wallpaper wechat applet two open repair version source code download support traffic main revenue

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

Take you ten days to easily complete the go micro service series (IX. link tracking)

Roads and routes -- dfs+topsort+dijkstra+ mapping
![抓包整理外篇——————状态栏[ 四]](/img/88/8267ab92177788ac17ab665a90b781.png)
抓包整理外篇——————状态栏[ 四]

Postman automatically fills headers
![[OpenGL learning notes 8] texture](/img/77/a4a784a535ea6f4c2382857b266cec.jpg)
[OpenGL learning notes 8] texture

Arbitrum: two-dimensional cost

Armv8-a programming guide MMU (3)
随机推荐
Introduction to the gtid mode of MySQL master-slave replication
[wave modeling 2] three dimensional wave modeling and wave generator modeling matlab simulation
[development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39
实战模拟│JWT 登录认证
【纯音听力测试】基于MATLAB的纯音听力测试系统
Global and Chinese markets of emergency rescue vessels (errv) 2022-2028: Research Report on technology, participants, trends, market size and share
Redis master-slave replication cluster and recovery ideas for abnormal data loss # yyds dry goods inventory #
Phpstrom setting function annotation description
[OpenGL learning notes 8] texture
When the industrial Internet era is truly developed and improved, it will witness the birth of giants in every scene
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
To sort out messy header files, I use include what you use
Arbitrum:二维费用
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
[FPGA tutorial case 9] design and implementation of clock manager based on vivado core
node工程中package.json文件作用是什么?里面的^尖括号和~波浪号是什么意思?
Postman automatically fills headers
Check if this is null - checking if this is null
Basic operations of database and table ----- create index
Exploration and Practice of Stream Batch Integration in JD