[CSHARP-367] Make collection parameter optional in constructor for MongoInsertOptions and MongoUpdateOptions Created: 16/Dec/11 Updated: 02/Apr/15 Resolved: 29/Dec/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.3.1 |
| Fix Version/s: | 1.4 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Robert Stam | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Major Change |
| Description |
|
The constructors for MongoInsertOptions and MongoUpdateOptions take a collection parameter for the purpose of inheriting some of the values from the collection. But this results in having to specify the collection twice in code like the following:
It would be nicer (and shorter) to just write:
This does mean that the options class will NOT be filled in with default values from the collection, so the properties of the options class will be null unless set to a value by your code. The collection class will know to fetch default values from the collection for any values to explicitly set in the options class. |
| Comments |
| Comment by Robert Stam [ 29/Dec/11 ] |
|
Fixed by merging in Alexander Nagy's pull request. |
| Comment by Alexander Nagy [ 16/Dec/11 ] |
|
Just submitted the pull request for this, addressed the backwards compatibility issue by marking the deprecated constructors with [Obsolete] which will give callers a warning until the API is removed. |
| Comment by Robert Stam [ 16/Dec/11 ] |
|
Right. The collection would use it's own values for any options not set. The only issue with removing the constructors that take a collection is backward compatibility... The options are already optional on the Insert method. If we were requiring C# 4 we could handle optional options without an additional overload using C# 4's support for optional parameters. |
| Comment by Craig Wilson [ 16/Dec/11 ] |
|
So, the collection class would use it's values unless otherwise specified in the options class... This makes sense and, quite frankly, I'd be an advocate of deprecating the options constructors that take the collection. To further this idea, options should be optional on the Insert method because the collection contains all the defaults. |