[CSHARP-276] BsonArray should have constructor/methods dealing with not-generic IEnumerable Created: 21/Jul/11  Updated: 02/Apr/15  Resolved: 22/Jul/11

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

Type: Improvement Priority: Minor - P4
Reporter: Roman Kuzmin Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows PowerShell (for sure), C# (maybe)


Backwards Compatibility: Minor Change

 Description   

Lack of such a constructor and methods makes it difficult to create a BsonArray or add a range of values to an existing instance in PowerShell scripts. PowerShell V1, V2 does not support generics well.

Perhaps, even in C# (at least before 4.0), with only System.Collection.IEnumerable at hand there may be similar difficulties. But I did not try that.



 Comments   
Comment by Roman Kuzmin [ 23/Jul/11 ]

Great!

Perhaps it make sense now to retire BsonArray methods dealing with IEnumerable<object> (constructor, Create, and AddRange), they all do the same job as the new methods with IEnumerable.

Such a change is potentially breaking for existing assemblies that call one of IEnumerable<object> methods (I have not tried). But it should be enough simply to rebuild such assemblies from sources, source changes are not needed (I have tried to remove IEnumerable<object> methods in the driver sources and build after that).

Comment by Robert Stam [ 22/Jul/11 ]

Added overloads of the BsonArray constructor and AddRange and Create methods that take a non-generic IEnumerable parameter. Also removed the BsonDocumentToBsonArray mapping in BsonTypeMapper because it conflicts with the new IEnumerable overloads (and it was a rather far-fetched mapping anyway).

NOTE: this change is backward breaking only in the very remote case that you were using the BsonDocumentToBsonArray mapping of the BsonTypeMapper. If you were, just pass document.Values instead of document as the argument instead.

Comment by Roman Kuzmin [ 22/Jul/11 ]

It is good to know that PowerShell is not forgotten. With MongoDB + C# driver + PowerShell a lot of data-oriented tasks become ridiculously easy (RDBMSs normally require more knowledge and skills). PowerShell is preinstalled and ready to use in latest Windows versions. For some audience it might be the only programming tool practically available, e.g. for system administrators, casual users, not programmers per se.

Comment by Robert Stam [ 21/Jul/11 ]

These were originally left out because they require mapping each value from type object to BsonValue at run time (and the generic types allow us to map at compile time). But that was before we made being Powershell friendly a priority. I will investigate.

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