Adding null/empty checks to some controls to prevent invalid behaviour

This commit is contained in:
Florian Zevedei
2024-06-09 14:19:04 +02:00
parent 834038ff44
commit 6adcc52ea2
10 changed files with 130 additions and 22 deletions
+7 -1
View File
@@ -16,7 +16,7 @@ public class Label : ControlBase
{
private bool _renderNecessary = true;
private string _text = string.Empty;
private string _text = Default.Language["Label_Text"];
public String Text
{
@@ -29,6 +29,10 @@ public class Label : ControlBase
if (_text == value)
return;
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException($"{nameof(Text)}", $"{nameof(Text)} property must have been a value unequal to null/empty");
}
_text = value;
_renderNecessary = true;
@@ -36,6 +40,8 @@ public class Label : ControlBase
}
}
private ParseMode _parseMode = ParseMode.Markdown;
public ParseMode ParseMode
@@ -32,10 +32,32 @@ public class MultiToggleButton : ControlBase
/// </summary>
public string ChangedString { get; set; } = Default.Language["MultiToggleButton_Changed"];
private string _title = Default.Language["MultiToggleButton_Title"];
/// <summary>
/// This holds the title of the control.
/// </summary>
public string Title { get; set; } = Default.Language["MultiToggleButton_Title"];
public String Title
{
get
{
return _title;
}
set
{
if (_title == value)
return;
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} must have been a value unequal to null/empty");
}
_title = value;
_renderNecessary = true;
}
}
public int? MessageId { get; set; }
@@ -36,7 +36,31 @@ public class ToggleButton : ControlBase
public string ChangedString { get; set; } = Default.Language["ToggleButton_Changed"];
public string Title { get; set; } = Default.Language["ToggleButton_Title"];
private string _title = Default.Language["ToggleButton_Title"];
public String Title
{
get
{
return _title;
}
set
{
if (_title == value)
return;
if (string.IsNullOrEmpty(value))
{
throw new ArgumentNullException($"{nameof(Title)}", $"{nameof(Title)} property must have been a value unequal to null/empty");
}
_title = value;
_renderNecessary = true;
}
}
public int? MessageId { get; set; }