Last active
June 30, 2021 01:48
-
-
Save runceel/31818bc13a4c9bab14a0bf71a1b91017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
namespace ArgTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var h = new Humidifier(); | |
h.SetModeAsync("id", DeviceMode.Auto); | |
h.SetModeAsync("id", DeviceMode.Value101); | |
h.SetModeAsync("id", DeviceMode.Value102); | |
h.SetModeAsync("id", DeviceMode.Value103); | |
h.SetModeAsync("id", DeviceMode.PercentageMode(33)); | |
} | |
} | |
public class Humidifier | |
{ | |
public Task<CommandExecuteResoponse> SetModeAsync(string deviceId, DeviceMode mode) | |
{ | |
var parameter = mode.Value; | |
return Task.FromResult(new CommandExecuteResoponse()); | |
} | |
} | |
public struct DeviceMode | |
{ | |
private static DeviceMode s_auto = new DeviceMode("auto"); | |
private static DeviceMode s_101 = new DeviceMode("101"); | |
private static DeviceMode s_102 = new DeviceMode("102"); | |
private static DeviceMode s_103 = new DeviceMode("103"); | |
public string Value { get; } | |
DeviceMode(string value) | |
{ | |
Value = value; | |
} | |
public static DeviceMode PercentageMode(int percentage) | |
{ | |
if (percentage < 0 || percentage > 100) { throw new ArgumentOutOfRangeException(nameof(percentage)); } | |
return new DeviceMode(percentage.ToString()); | |
} | |
public static DeviceMode Auto => s_auto; | |
public static DeviceMode Value101 => s_101; | |
public static DeviceMode Value102 => s_102; | |
public static DeviceMode Value103 => s_103; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment