[CSHARP-1125] Add an implicit conversion from string to BsonDocument that parses the string Created: 20/Nov/14  Updated: 25/Mar/19  Resolved: 25/Mar/19

Status: Closed
Project: C# Driver
Component/s: BSON, Serialization
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Robert Stam Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The new CRUD API allows you to use strings where a document is expected, and converts the string to a BsonDocument by assuming it is a JSON string and parsing it.

If we want to make it easy to provide BsonDocument values using strings in as many places as possible we might as well provide an implicit conversion from string to BsonDocument that parses the string.

Before actually implementing this we should consider whether this would result in a big hole in type safety. The issue is that if one accidentally writes code that uses a string where a BsonDocument is expected one would no longer get a compile time error (one would likely get a runtime error if the string doesn't happen to be a valid JSON document). On the other hand, being able to provide BsonDocuments using string constants would be incredibly convenient.

The other issue is that parsing strings to provide BsonDocument values involves the considerable overhead of parsing the string, and if we make it too easy to convert strings to BsonDocuments we may be encouraging our users to write inefficient code.



 Comments   
Comment by Ian Whalen (Inactive) [ 25/Mar/19 ]

Given the lack of votes or activity on this idea (and that it would be somewhat unsafe because it sacrifices some type safety) we are closing as won't fix.

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