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> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net7.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

@ -4,42 +4,55 @@ using System.Text;
namespace BitMaskTest namespace BitMaskTest
{ {
[Flags] // [Flags]
public enum ButtonMask // public enum ButtonMask
{ // {
None = 0x00, // None = 0x00,
Remove = 0x01, // Remove = 0x01,
LevelUp = 0x02, // LevelUp = 0x02,
Change = 0x04, // Change = 0x04,
Reset = 0x08, // Reset = 0x08,
Cancel = 0x10, // Cancel = 0x10,
} // }
class PopupButtonMask [Flags]
{ public enum ButtonMask
public ButtonMask Mask { get; set; } = ButtonMask.None; {
None = 0,
public List<ButtonMask> GetButtons() Remove = 1 << 0,
{ LevelUp = 1 << 1,
List<ButtonMask> buttons = new List<ButtonMask>(); Change = 1 << 2,
foreach (ButtonMask flag in Enum.GetValues(typeof(ButtonMask))) Reset = 1 << 3,
{ Cancel = 1 << 4,
if (checkMask(flag))
buttons.Add(flag); All = int.MaxValue
} }
if (buttons == null || buttons.Count < 1) class PopupButtonMask
return null; {
public ButtonMask Mask { get; set; } = ButtonMask.None;
return buttons;
} public List<ButtonMask> GetButtons()
{
private bool checkMask(ButtonMask compareTarget) List<ButtonMask> buttons = new List<ButtonMask>();
{ foreach (ButtonMask flag in Enum.GetValues(typeof(ButtonMask)))
int flags = (int)this.Mask; {
int flag = (int)compareTarget; if (checkMask(flag))
buttons.Add(flag);
return (flags & flag) != 0; }
}
} 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 namespace BitMaskTest
{ {
/* /*
* AND &: 1 1 * AND &: 1 1
* 1011 & 1001 = 1001 * 1011 & 1001 = 1001
* *
@ -20,20 +20,20 @@ namespace BitMaskTest
* 001011 << 2 = 101100 * 001011 << 2 = 101100
* 001011 >> 2 = 000010 * 001011 >> 2 = 000010
*/ */
class Program class Program
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
PopupButtonMask popupButton = new PopupButtonMask(); PopupButtonMask popupButton = new PopupButtonMask();
popupButton.Mask = ButtonMask.LevelUp | ButtonMask.Reset | ButtonMask.Cancel | ButtonMask.Remove | ButtonMask.Change; popupButton.Mask = ButtonMask.LevelUp | ButtonMask.Cancel | ButtonMask.Remove | ButtonMask.Change;
List<ButtonMask> buttons = popupButton.GetButtons(); System.Console.WriteLine(popupButton.checkMask(ButtonMask.All));
foreach (ButtonMask item in buttons)
{
Console.WriteLine(item);
}
Console.ReadKey(); // List<ButtonMask> buttons = popupButton.GetButtons();
} // foreach (ButtonMask item in buttons)
} // {
// Console.WriteLine(item);
// }
}
}
} }

Loading…
Cancel
Save