update code

master
syneffort 2 years ago
parent fa53570753
commit 957ec8482b
  1. 24
      BitMaskTest/.vscode/launch.json
  2. 41
      BitMaskTest/.vscode/tasks.json
  3. 2
      BitMaskTest/BitMaskTest.csproj
  4. 89
      BitMaskTest/PopupButtonMask.cs
  5. 30
      BitMaskTest/Program.cs

@ -0,0 +1,24 @@
{
// IntelliSense .
// .
// https://go.microsoft.com/fwlink/?linkid=830387() .
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net7.0/BitMaskTest.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/BitMaskTest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/BitMaskTest.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/BitMaskTest.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
</Project>

@ -4,42 +4,55 @@ using System.Text;
namespace BitMaskTest
{
[Flags]
public enum ButtonMask
{
None = 0x00,
Remove = 0x01,
LevelUp = 0x02,
Change = 0x04,
Reset = 0x08,
Cancel = 0x10,
}
class PopupButtonMask
{
public ButtonMask Mask { get; set; } = ButtonMask.None;
public List<ButtonMask> GetButtons()
{
List<ButtonMask> buttons = new List<ButtonMask>();
foreach (ButtonMask flag in Enum.GetValues(typeof(ButtonMask)))
{
if (checkMask(flag))
buttons.Add(flag);
}
if (buttons == null || buttons.Count < 1)
return null;
return buttons;
}
private bool checkMask(ButtonMask compareTarget)
{
int flags = (int)this.Mask;
int flag = (int)compareTarget;
return (flags & flag) != 0;
}
}
// [Flags]
// public enum ButtonMask
// {
// None = 0x00,
// Remove = 0x01,
// LevelUp = 0x02,
// Change = 0x04,
// Reset = 0x08,
// Cancel = 0x10,
// }
[Flags]
public enum ButtonMask
{
None = 0,
Remove = 1 << 0,
LevelUp = 1 << 1,
Change = 1 << 2,
Reset = 1 << 3,
Cancel = 1 << 4,
All = int.MaxValue
}
class PopupButtonMask
{
public ButtonMask Mask { get; set; } = ButtonMask.None;
public List<ButtonMask> GetButtons()
{
List<ButtonMask> buttons = new List<ButtonMask>();
foreach (ButtonMask flag in Enum.GetValues(typeof(ButtonMask)))
{
if (checkMask(flag))
buttons.Add(flag);
}
if (buttons == null || buttons.Count < 1)
return null;
return buttons;
}
public bool checkMask(ButtonMask compareTarget)
{
int flags = (int)this.Mask;
int flag = (int)compareTarget;
return (flags & flag) != 0;
}
}
}

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace BitMaskTest
{
/*
/*
* AND &: 1 1
* 1011 & 1001 = 1001
*
@ -20,20 +20,20 @@ namespace BitMaskTest
* 001011 << 2 = 101100
* 001011 >> 2 = 000010
*/
class Program
{
static void Main(string[] args)
{
PopupButtonMask popupButton = new PopupButtonMask();
popupButton.Mask = ButtonMask.LevelUp | ButtonMask.Reset | ButtonMask.Cancel | ButtonMask.Remove | ButtonMask.Change;
class Program
{
static void Main(string[] args)
{
PopupButtonMask popupButton = new PopupButtonMask();
popupButton.Mask = ButtonMask.LevelUp | ButtonMask.Cancel | ButtonMask.Remove | ButtonMask.Change;
List<ButtonMask> buttons = popupButton.GetButtons();
foreach (ButtonMask item in buttons)
{
Console.WriteLine(item);
}
System.Console.WriteLine(popupButton.checkMask(ButtonMask.All));
Console.ReadKey();
}
}
// List<ButtonMask> buttons = popupButton.GetButtons();
// foreach (ButtonMask item in buttons)
// {
// Console.WriteLine(item);
// }
}
}
}

Loading…
Cancel
Save