Best practice for passing enum params in Web API

前端 未结 4 1846
北恋
北恋 2021-01-07 16:31

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:22

    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.

提交回复
热议问题