当前位置:网站首页>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边栏推荐
- Database postragesq role membership
- What sparks can applet container technology collide with IOT
- To sort out messy header files, I use include what you use
- Basic operations of database and table ----- create index
- 无心剑英译席慕容《无怨的青春》
- Grabbing and sorting out external articles -- status bar [4]
- FEG founder rox:smartdefi will be the benchmark of the entire decentralized financial market
- JS implementation determines whether the point is within the polygon range
- Wechat applet: independent background with distribution function, Yuelao office blind box for making friends
- Talking about JVM 4: class loading mechanism
猜你喜欢

What sparks can applet container technology collide with IOT

Kibana installation and configuration

【海浪建模2】三维海浪建模以及海浪发电机建模matlab仿真

增量备份 ?db full
![[development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39](/img/60/d5951ffb4cc271d2e7a3add9293f23.png)
[development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39
![[development of large e-commerce projects] performance pressure test - Optimization - impact of middleware on performance -40](/img/e4/0bdee782a65028b2bc87db85d48738.png)
[development of large e-commerce projects] performance pressure test - Optimization - impact of middleware on performance -40
![Yyds dry goods inventory [Gan Di's one week summary: the most complete and detailed in the whole network]; detailed explanation of MySQL index data structure and index optimization; remember collectio](/img/e8/de158982788fc5bc42f842b07ff9a8.jpg)
Yyds dry goods inventory [Gan Di's one week summary: the most complete and detailed in the whole network]; detailed explanation of MySQL index data structure and index optimization; remember collectio

Postman automatically fills headers

Wechat applet: new independent backstage Yuelao office one yuan dating blind box

【纯音听力测试】基于MATLAB的纯音听力测试系统
随机推荐
Poap: the adoption entrance of NFT?
Phpstrom setting function annotation description
Introduction to the gtid mode of MySQL master-slave replication
[untitled]
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
微信小程序;胡言乱语生成器
Database postragesql client connection default
【微处理器】基于FPGA的微处理器VHDL开发
Are you still writing the TS type code
Introduction to the gtid mode of MySQL master-slave replication
dotnet-exec 0.6.0 released
Introduction to redis (1)
Exploration and Practice of Stream Batch Integration in JD
Delaying wages to force people to leave, and the layoffs of small Internet companies are a little too much!
微信小程序:星宿UI V1.5 wordpress系统资讯资源博客下载小程序微信QQ双端源码支持wordpress二级分类 加载动画优化
【CTF】AWDP总结(Web)
Change the background color of a pop-up dialog
Database postragesq peer authentication
微信小程序:全新独立后台月老办事处一元交友盲盒
Global and Chinese market of veterinary thermometers 2022-2028: Research Report on technology, participants, trends, market size and share