ToString fancy

This commit is contained in:
2024-02-12 03:06:28 +01:00
parent 2c7da0352b
commit eebf15804a
4 changed files with 35 additions and 24 deletions

View File

@ -32,14 +32,15 @@ public class OpenShockShocker : Shocker
public override string ToString()
{
return $"{string.Join("\n\t",
$"{GetType().Name}",
$"Name: {Name}",
$"ID: {ID}",
$"RF-ID: {RfId}",
$"Model: {Enum.GetName(Model)}",
$"Created On: {CreatedOn}",
$"Paused: {IsPaused}")}" +
const int tabWidth = -12;
return $"\t{string.Join("\n\t",
$"\u251c {"Type",tabWidth}: {GetType().Name}",
$"\u251c {"Name",tabWidth}: {Name}",
$"\u251c {"ID",tabWidth}: {ID}",
$"\u251c {"RF-ID",tabWidth}: {RfId}",
$"\u251c {"Model",tabWidth}: {Enum.GetName(Model)}",
$"\u251c {"Created On",tabWidth}: {CreatedOn}",
$"\u2514 {"Paused",tabWidth}: {IsPaused}")}" +
$"\n\r";
}

View File

@ -7,6 +7,13 @@ public class PiShockShocker : Shocker
{
public readonly string Code;
public PiShockShocker(Api api, string code) : base(api)
{
if (api is not PiShockApi)
throw new Exception($"API-Type {api.GetType().FullName} is not usable with Shocker {this.GetType().FullName}");
Code = code;
}
public override bool Equals(object? obj)
{
return obj is PiShockShocker pss && Equals(pss);
@ -21,11 +28,13 @@ public class PiShockShocker : Shocker
{
return Code.GetHashCode();
}
public PiShockShocker(Api api, string code) : base(api)
public override string ToString()
{
if (api is not PiShockApi)
throw new Exception($"API-Type {api.GetType().FullName} is not usable with Shocker {this.GetType().FullName}");
Code = code;
const int tabWidth = -5;
return $"{string.Join("\n\t",
$"\u251c {"Type",tabWidth}: {GetType().Name}",
$"\u2514 {"Code",tabWidth}: {Code}")}" +
$"\n\r";
}
}