Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-682

Enum support for Update<T>.BitwiseAnd and Update<T>.BitwiseOr



    • Backwards Compatibility:
      Fully Compatible


      I am using MongoCollection<T> in my project a lot, where T are my root domain objects (ie. not BsonDocument). In one instance, I am trying to use flags to indicate data such as user roles. As roles are not mutually exclusive in this particular case, they are designed as enums with the [Flags] attribute to allow for multiple roles. For example:

      public enum Roles
          User = 0x00,
          Moderator = 0x01,
          Administrator = 0x02,
          SomeOtherRole = 0x04,
          /* etc */

      As I was trying to do an Update<T>.BitwiseAnd or Update<T>.BitwiseOr, I noticed that the method only takes Func<T, int> or Func<T, long> as their first argument and int or long as their second. Since my models make use of enums, expressions like these make my compiler unhappy:

      userCollection.FindAndModify(..., ..., Update<User>.BitwiseOr(x => x.Roles, roles));

      (This snippet is of course abbreviated, there's Query<T> and SortBy<T> expressions instead of just ellipses. "roles" is an instance of that Enumeration here.)

      I would be happy if you would consider directly supporting enumerations in this use case that does not require me to make use of int or long in my models to represent flags.




            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: