当前位置:网站首页>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边栏推荐
- Yyds dry goods inventory kubernetes management business configuration methods? (08)
- Armv8-a programming guide MMU (3)
- Es uses collapsebuilder to de duplicate and return only a certain field
- Take you ten days to easily complete the go micro service series (IX. link tracking)
- Global and Chinese market of optical densitometers 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of network connected IC card smart water meters 2022-2028: Research Report on technology, participants, trends, market size and share
- [swagger]-swagger learning
- Robley's global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
- [development of large e-commerce projects] performance pressure test - Performance Monitoring - heap memory and garbage collection -39
- Jcenter () cannot find Alibaba cloud proxy address
猜你喜欢

DOM basic syntax

Wechat applet: wechat applet source code download new community system optimized version support agent member system function super high income

FEG founder rox:smartdefi will be the benchmark of the entire decentralized financial market

Remote control service

Senior Test / development programmers write no bugs? Qualifications (shackles) don't be afraid of mistakes

Blue Bridge Cup Square filling (DFS backtracking)

流批一體在京東的探索與實踐

Game 280 of leetcode week

The performance of major mainstream programming languages is PK, and the results are unexpected

dotnet-exec 0.6.0 released
随机推荐
C basic knowledge review (Part 3 of 4)
微信小程序:全新独立后台月老办事处一元交友盲盒
Arbitrum: two-dimensional cost
PHP Basics - detailed explanation of DES encryption and decryption in PHP
Query for Boolean field as "not true" (e.g. either false or non-existent)
PHP 约瑟夫环问题
POAP:NFT的采用入口?
如果消费互联网比喻成「湖泊」的话,产业互联网则是广阔的「海洋」
流批一体在京东的探索与实践
Call Huawei order service to verify the purchase token interface and return connection reset
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
Analysis and comparison of leetcode weekly race + acwing weekly race (t4/t3)
[FPGA tutorial case 10] design and implementation of complex multiplier based on Verilog
Complex, complicated and numerous: illustration of seven types of code coupling
How to use words to describe breaking change in Spartacus UI of SAP e-commerce cloud
Basic operations of database and table ----- create index
【海浪建模3】三维随机真实海浪建模以及海浪发电机建模matlab仿真
Kibana installation and configuration
Behind the cluster listing, to what extent is the Chinese restaurant chain "rolled"?