[CSHARP-813] Add TryParse method to WriteConcern class Created: 03/Sep/13  Updated: 20/Mar/14  Resolved: 20/Mar/14

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.8.2
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Rasitha Wijesinghe Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

windows/.net



 Description   

Can you add a TryParse method to WriteConcern class so a string can be converted to a matching WriteConcern value? (Similar to Enum.TryParse) This will help when db settings are stored elsewhere and we have to convert in code (ex. values coming from a xml file).



 Comments   
Comment by Craig Wilson [ 20/Mar/14 ]

Hi Rasitha,

Parse is a somewhat overloaded term here and we feel that opening this up could lead to us needing to parse many different variations of the same thing. We understand your concern, but don't believe this belongs in the driver. If you feel strongly, feel free to re-open the ticket and we'd be happy to continue the discussion.

Thanks,
CRaig

Comment by Rasitha Wijesinghe [ 03/Sep/13 ]

Acknowledged
Unacknowledged
W2
W3
W4
WMajority

So in code I could do something like this:

WriteConcern w;
if(WriteConcern.TryParse(value, out w))
   return w;
 

Today I have to have a switch statement and if you add another W value, I'll have to change my code too.

If you are implementing TryParse, you could also implement Parse that would throw if not a valid value.

Comment by Craig Wilson [ 03/Sep/13 ]

Rasitha,
Could you perhaps provide a sample of what you would expect would be parsable? In other words, what type of string are you thinking you'd like to provide?

Generated at Wed Feb 07 21:37:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.