[CSHARP-819] DOCS: Case insensative string serialization in .NET driver Created: 11/Sep/13 Updated: 02/Feb/18 Resolved: 02/Feb/18 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 1.8.2 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Michael Kennedy | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
C# Driver |
||
| Backwards Compatibility: | Fully Compatible |
| Description |
|
I would like an attribute which controls string serialization to / from Mongo at the C# layer. Something like [BsonStringOptions(UseLowerCase = true)] The motivation: Here's some feedback from a new app I'm working on in C#. We are coming from SQL Server where most string comparisons are case insensitive. Obviously MongoDB is case sensitive. There are plenty of fields we want to continue case insensitive comps on. For example, usernames, emails, urls, etc. We are fine to just store them all lowercase. But having the serialization engine help ensure this would help. It would be great if there was an attribute that would help with this (kind of like [BsonDateTimeOptions(Kind = DateTimeKind.Local)] for UTC vs Local time). So I'd like to offer a new feature idea: class Model { } Where when this object is saved, it automatically converts to lowercase. I can do this in code, but it's a pain and potentially error prone. |
| Comments |
| Comment by Michael Kennedy [ 16/Sep/13 ] |
|
Thanks Craig. That's good to know. I'll see what I can whip up. It'd be nice to see it part of the official driver eventually. Cheers, |
| Comment by Craig Wilson [ 11/Sep/13 ] |
|
Hi Michael, You obviously don't want this serializer used for all strings. For this, you can create an attribute yourself by inheriting from Attribute and implementing IBsonMemberMapAttribute. You can then switch the serializer for this custom string one out inside the Apply method of the attribute. |