假设我有以下内容
int susan = 2; //0010
int bob = 4; //0100
int karen = 8; //1000
Run Code Online (Sandbox Code Playgroud)
我将10(8 + 2)作为参数传递给方法,我想将其解码为苏珊和卡伦
我知道10是1010
但是我如何做一些逻辑来查看是否检查了特定位
if (condition_for_karen) // How to quickly check whether effective karen bit is 1
Run Code Online (Sandbox Code Playgroud)
现在,我能想到的是检查我通过的号码是否正确
14 // 1110
12 // 1100
10 // 1010
8 // 1000
Run Code Online (Sandbox Code Playgroud)
当我在我的真实场景中拥有更多的实际比特时,这似乎是不切实际的,使用掩码来检查我是否满足karen条件的更好方法是什么?
我可以想到向左移动然后向后移动然后向右移动然后移回到除了我感兴趣的那个之外的其他位置,但这似乎也过于复杂.
有没有办法将所有枚举显示为swagger中的字符串值而不是int值?
我希望能够提交POST操作并根据其字符串值放置枚举,而不必每次都查看枚举.
我试过,DescribeAllEnumsAsStrings但服务器接收字符串而不是枚举值,这不是我们正在寻找的.
有人解决了这个吗?
编辑:
public class Letter
{
[Required]
public string Content {get; set;}
[Required]
[EnumDataType(typeof(Priority))]
public Priority Priority {get; set;}
}
public class LettersController : ApiController
{
[HttpPost]
public IHttpActionResult SendLetter(Letter letter)
{
// Validation not passing when using DescribeEnumsAsStrings
if (!ModelState.IsValid)
return BadRequest("Not valid")
..
}
// In the documentation for this request I want to see the string values of the enum before submitting: Low, Medium, High. Instead of 0, 1, 2
[HttpGet]
public …Run Code Online (Sandbox Code Playgroud)