Best practice for passing enum params in Web API

前端 未结 4 1656
迷失自我
迷失自我 2021-01-07 16:30

I have a RESTful Web API project, and I have 2 different Enum scenarios that I\'m unsure of re best practice.

Scenario 1 : Straightforward Enum Param

4条回答
  •  温柔的废话
    2021-01-07 17:16

    For scenario 2 there is built in support in C# for Bitmask operations in Enums using the [Flags] attribute

    [Flags]
    public enum OptionalField
    {
        None = 0,
        RuleOwner = 1,
        Rule = 2,
        RuleAdministrator = 4,
        RuleEditor = 8,
        ...etc
    }
    

    Which is described in this SO post

    As Christian already stated in his answer it's probably not good practice to use this in a REST API but it should work.

提交回复
热议问题