From 19bf33ec749e5041c9bf0de8b782d816c6393f29 Mon Sep 17 00:00:00 2001 From: Vikram Reddy Date: Sun, 23 Jul 2023 11:15:51 +0530 Subject: [PATCH] Models and Extensions - Cleanup --- blazorbootstrap/Extensions/EnumExtensions.cs | 174 ++++++++---------- .../Extensions/ExpressionExtensions.cs | 133 +++++-------- .../Models/AutoCompleteDataProviderResult.cs | 2 +- blazorbootstrap/Models/BreadcrumbItem.cs | 4 +- .../Models/GridDataProviderResult.cs | 2 +- blazorbootstrap/Models/NavItem.cs | 10 +- .../Models/SidebarDataProviderRequest.cs | 2 +- .../Models/SidebarDataProviderResult.cs | 2 +- blazorbootstrap/Models/ToastMessage.cs | 84 ++++----- 9 files changed, 168 insertions(+), 245 deletions(-) diff --git a/blazorbootstrap/Extensions/EnumExtensions.cs b/blazorbootstrap/Extensions/EnumExtensions.cs index f86e5ef52..240fba23d 100644 --- a/blazorbootstrap/Extensions/EnumExtensions.cs +++ b/blazorbootstrap/Extensions/EnumExtensions.cs @@ -7,140 +7,119 @@ public static class EnumExtensions /// /// /// string - public static string ToBackgroundClass(this BackgroundColor backgroundColor) + public static string ToBackgroundClass(this BackgroundColor backgroundColor) => backgroundColor switch { - return backgroundColor switch - { - BackgroundColor.Primary => "bg-primary", - BackgroundColor.Secondary => "bg-secondary", - BackgroundColor.Success => "bg-success", - BackgroundColor.Danger => "bg-danger", - BackgroundColor.Warning => "bg-warning", - BackgroundColor.Info => "bg-info", - BackgroundColor.Light => "bg-light", - BackgroundColor.Dark => "bg-dark", - BackgroundColor.Body => "bg-body", - BackgroundColor.White => "bg-white", - BackgroundColor.Transparent => "bg-transparent", + BackgroundColor.Primary => "bg-primary", + BackgroundColor.Secondary => "bg-secondary", + BackgroundColor.Success => "bg-success", + BackgroundColor.Danger => "bg-danger", + BackgroundColor.Warning => "bg-warning", + BackgroundColor.Info => "bg-info", + BackgroundColor.Light => "bg-light", + BackgroundColor.Dark => "bg-dark", + BackgroundColor.Body => "bg-body", + BackgroundColor.White => "bg-white", + BackgroundColor.Transparent => "bg-transparent", - _ => "" - }; - } + _ => "" + }; /// /// Get the background and text classes. /// /// /// string - public static string ToBackgroundAndTextClass(this BackgroundColor backgroundColor) + public static string ToBackgroundAndTextClass(this BackgroundColor backgroundColor) => backgroundColor switch { - return backgroundColor switch - { - BackgroundColor.Primary => "bg-primary text-white", - BackgroundColor.Secondary => "bg-secondary text-white", - BackgroundColor.Success => "bg-success text-white", - BackgroundColor.Danger => "bg-danger text-white", - BackgroundColor.Warning => "bg-warning text-dark", - BackgroundColor.Info => "bg-info text-dark", - BackgroundColor.Light => "bg-light text-dark", - BackgroundColor.Dark => "bg-dark text-white", - BackgroundColor.Body => "bg-body text-dark", - BackgroundColor.White => "bg-white text-dark", - BackgroundColor.Transparent => "bg-transparent text-dark", + BackgroundColor.Primary => "bg-primary text-white", + BackgroundColor.Secondary => "bg-secondary text-white", + BackgroundColor.Success => "bg-success text-white", + BackgroundColor.Danger => "bg-danger text-white", + BackgroundColor.Warning => "bg-warning text-dark", + BackgroundColor.Info => "bg-info text-dark", + BackgroundColor.Light => "bg-light text-dark", + BackgroundColor.Dark => "bg-dark text-white", + BackgroundColor.Body => "bg-body text-dark", + BackgroundColor.White => "bg-white text-dark", + BackgroundColor.Transparent => "bg-transparent text-dark", - _ => "" - }; - } + _ => "" + }; /// /// Gets the button class. /// /// /// string - public static string ToButtonClass(this ButtonColor buttonColor) + public static string ToButtonClass(this ButtonColor buttonColor) => buttonColor switch { - return buttonColor switch - { - ButtonColor.Primary => "btn btn-primary", - ButtonColor.Secondary => "btn btn-secondary", - ButtonColor.Success => "btn btn-success", - ButtonColor.Danger => "btn btn-danger", - ButtonColor.Warning => "btn btn-warning", - ButtonColor.Info => "btn btn-info", - ButtonColor.Light => "btn btn-light", - ButtonColor.Dark => "btn btn-dark", - ButtonColor.Link => "btn btn-link", + ButtonColor.Primary => "btn btn-primary", + ButtonColor.Secondary => "btn btn-secondary", + ButtonColor.Success => "btn btn-success", + ButtonColor.Danger => "btn btn-danger", + ButtonColor.Warning => "btn btn-warning", + ButtonColor.Info => "btn btn-info", + ButtonColor.Light => "btn btn-light", + ButtonColor.Dark => "btn btn-dark", + ButtonColor.Link => "btn btn-link", - _ => "btn btn-primary" - }; - } + _ => "btn btn-primary" + }; /// /// Gets the button tag name. /// /// /// string - public static string ToButtonTagName(this ButtonType buttonType) + public static string ToButtonTagName(this ButtonType buttonType) => buttonType switch { - return buttonType switch - { - ButtonType.Link => "a", - _ => "button" - }; - } + ButtonType.Link => "a", + _ => "button" + }; /// /// Gets the button type. /// /// /// string - public static string ToButtonTypeString(this ButtonType buttonType) + public static string ToButtonTypeString(this ButtonType buttonType) => buttonType switch { - return buttonType switch - { - ButtonType.Button => "button", - ButtonType.Submit => "submit", - ButtonType.Reset => "reset", - _ => null, - }; - } + ButtonType.Button => "button", + ButtonType.Submit => "submit", + ButtonType.Reset => "reset", + _ => null, + }; /// /// Gets the callout color. /// /// /// string - public static string ToCalloutColor(this CalloutType calloutColor) + public static string ToCalloutColor(this CalloutType calloutColor) => calloutColor switch { - return calloutColor switch - { - CalloutType.Default => "", - CalloutType.Danger => "bb-callout-danger", - CalloutType.Warning => "bb-callout-warning", - CalloutType.Info => "bb-callout-info", - _ => "" - }; - } + CalloutType.Default => "", + CalloutType.Danger => "bb-callout-danger", + CalloutType.Warning => "bb-callout-warning", + CalloutType.Info => "bb-callout-info", + _ => "" + }; /// /// Gets the spinner color. /// /// /// string - public static string ToSpinnerColor(this SpinnerColor color) + public static string ToSpinnerColor(this SpinnerColor color) => color switch { - return color switch - { - SpinnerColor.Primary => "text-primary", - SpinnerColor.Secondary => "text-secondary", - SpinnerColor.Success => "text-success", - SpinnerColor.Danger => "text-danger", - SpinnerColor.Warning => "text-warning", - SpinnerColor.Info => "text-info", - SpinnerColor.Light => "text-light", - SpinnerColor.Dark => "text-dark", - _ => "" - }; - } + SpinnerColor.Primary => "text-primary", + SpinnerColor.Secondary => "text-secondary", + SpinnerColor.Success => "text-success", + SpinnerColor.Danger => "text-danger", + SpinnerColor.Warning => "text-warning", + SpinnerColor.Info => "text-info", + SpinnerColor.Light => "text-light", + SpinnerColor.Dark => "text-dark", + _ => "" + }; /// /// Gets the link target name. @@ -161,15 +140,12 @@ public static string ToSpinnerColor(this SpinnerColor color) /// /// /// string - public static string ToTooltipPlacementName(this TooltipPlacement tooltipPlacement) + public static string ToTooltipPlacementName(this TooltipPlacement tooltipPlacement) => tooltipPlacement switch { - return tooltipPlacement switch - { - TooltipPlacement.Auto => "auto", - TooltipPlacement.Right => "right", - TooltipPlacement.Bottom => "bottom", - TooltipPlacement.Left => "left", - _ => "top" - }; - } + TooltipPlacement.Auto => "auto", + TooltipPlacement.Right => "right", + TooltipPlacement.Bottom => "bottom", + TooltipPlacement.Left => "left", + _ => "top" + }; } diff --git a/blazorbootstrap/Extensions/ExpressionExtensions.cs b/blazorbootstrap/Extensions/ExpressionExtensions.cs index 567a3bd58..e4a863ce1 100644 --- a/blazorbootstrap/Extensions/ExpressionExtensions.cs +++ b/blazorbootstrap/Extensions/ExpressionExtensions.cs @@ -26,16 +26,16 @@ public static Expression> Or(this Expression> GetExpressionDelegate(ParameterExpression parameterExpression, FilterItem filterItem) + public static Expression>? GetExpressionDelegate(ParameterExpression parameterExpression, FilterItem filterItem) { var propertyTypeName = typeof(TItem).GetPropertyTypeName(filterItem.PropertyName); - if (propertyTypeName == StringConstants.PropertyTypeNameInt16 - || propertyTypeName == StringConstants.PropertyTypeNameInt32 - || propertyTypeName == StringConstants.PropertyTypeNameInt64 - || propertyTypeName == StringConstants.PropertyTypeNameSingle - || propertyTypeName == StringConstants.PropertyTypeNameDecimal - || propertyTypeName == StringConstants.PropertyTypeNameDouble) + if (propertyTypeName is StringConstants.PropertyTypeNameInt16 + or StringConstants.PropertyTypeNameInt32 + or StringConstants.PropertyTypeNameInt64 + or StringConstants.PropertyTypeNameSingle + or StringConstants.PropertyTypeNameDecimal + or StringConstants.PropertyTypeNameDouble) { return filterItem.Operator switch { @@ -48,8 +48,8 @@ public static Expression> GetExpressionDelegate(Paramet _ => GetNumberEqualExpressionDelegate(parameterExpression, filterItem, propertyTypeName), }; } - else if (propertyTypeName == StringConstants.PropertyTypeNameString - || propertyTypeName == StringConstants.PropertyTypeNameChar) + else if (propertyTypeName is StringConstants.PropertyTypeNameString + or StringConstants.PropertyTypeNameChar) { return filterItem.Operator switch { @@ -60,8 +60,8 @@ public static Expression> GetExpressionDelegate(Paramet _ => GetStringContainsExpressionDelegate(parameterExpression, filterItem), }; } - else if (propertyTypeName == StringConstants.PropertyTypeNameDateOnly - || propertyTypeName == StringConstants.PropertyTypeNameDateTime) + else if (propertyTypeName is StringConstants.PropertyTypeNameDateOnly + or StringConstants.PropertyTypeNameDateTime) { return filterItem.Operator switch { @@ -95,15 +95,9 @@ public static Expression> GetNumberEqualExpressionDelegate> GetNumberNotEqualExpressionDelegate< var constantExpression = GetNumberConstantExpression(filterItem, propertyTypeName); // Handle null check - Expression nullCheckExpression; - if (propertyExpression.Type.IsNullableType()) - { - nullCheckExpression = Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)); - } - else - { - nullCheckExpression = Expression.Constant(true); - } + var nullCheckExpression = propertyExpression.Type.IsNullableType() + ? Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)) + : (Expression)Expression.Constant(true); // Perform the greater than or equal comparison Expression comparisonExpression; @@ -159,15 +147,9 @@ public static Expression> GetNumberLessThanExpressionDelegate< var constantExpression = GetNumberConstantExpression(filterItem, propertyTypeName); // Handle null check - Expression nullCheckExpression; - if (propertyExpression.Type.IsNullableType()) - { - nullCheckExpression = Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)); - } - else - { - nullCheckExpression = Expression.Constant(true); - } + var nullCheckExpression = propertyExpression.Type.IsNullableType() + ? Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)) + : (Expression)Expression.Constant(true); // Perform the greater than or equal comparison Expression comparisonExpression; @@ -191,15 +173,9 @@ public static Expression> GetNumberLessThanOrEqualExpressionDe var constantExpression = GetNumberConstantExpression(filterItem, propertyTypeName); // Handle null check - Expression nullCheckExpression; - if (propertyExpression.Type.IsNullableType()) - { - nullCheckExpression = Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)); - } - else - { - nullCheckExpression = Expression.Constant(true); - } + var nullCheckExpression = propertyExpression.Type.IsNullableType() + ? Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)) + : (Expression)Expression.Constant(true); // Perform the greater than or equal comparison Expression comparisonExpression; @@ -223,15 +199,9 @@ public static Expression> GetNumberGreaterThanExpressionDelega var constantExpression = GetNumberConstantExpression(filterItem, propertyTypeName); // Handle null check - Expression nullCheckExpression; - if (propertyExpression.Type.IsNullableType()) - { - nullCheckExpression = Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)); - } - else - { - nullCheckExpression = Expression.Constant(true); - } + var nullCheckExpression = propertyExpression.Type.IsNullableType() + ? Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)) + : (Expression)Expression.Constant(true); // Perform the greater than or equal comparison Expression comparisonExpression; @@ -255,15 +225,9 @@ public static Expression> GetNumberGreaterThanOrEqualExpressio var constantExpression = GetNumberConstantExpression(filterItem, propertyTypeName); // Handle null check - Expression nullCheckExpression; - if (propertyExpression.Type.IsNullableType()) - { - nullCheckExpression = Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)); - } - else - { - nullCheckExpression = Expression.Constant(true); - } + var nullCheckExpression = propertyExpression.Type.IsNullableType() + ? Expression.NotEqual(propertyExpression, Expression.Constant(null, propertyExpression.Type)) + : (Expression)Expression.Constant(true); // Perform the greater than or equal comparison Expression comparisonExpression; @@ -281,46 +245,43 @@ public static Expression> GetNumberGreaterThanOrEqualExpressio return Expression.Lambda>(finalExpression, parameterExpression); } - public static bool IsNullableType(this Type type) - { - return Nullable.GetUnderlyingType(type) != null; - } + public static bool IsNullableType(this Type type) => Nullable.GetUnderlyingType(type) != null; public static ConstantExpression GetNumberConstantExpression(FilterItem filterItem, string propertyTypeName) { if (filterItem.Value is null) return Expression.Constant(null); - ConstantExpression constantExpression = null; + ConstantExpression? constantExpression = null; if (propertyTypeName == StringConstants.PropertyTypeNameInt16) { - _ = short.TryParse(filterItem.Value, out short filterValue); + _ = short.TryParse(filterItem.Value, out var filterValue); constantExpression = Expression.Constant((short?)filterValue); } else if (propertyTypeName == StringConstants.PropertyTypeNameInt32) { - _ = int.TryParse(filterItem.Value, out int filterValue); + _ = int.TryParse(filterItem.Value, out var filterValue); constantExpression = Expression.Constant((int?)filterValue); } else if (propertyTypeName == StringConstants.PropertyTypeNameInt64) { - _ = long.TryParse(filterItem.Value, out long filterValue); + _ = long.TryParse(filterItem.Value, out var filterValue); constantExpression = Expression.Constant((long?)filterValue); } else if (propertyTypeName == StringConstants.PropertyTypeNameSingle) { - _ = float.TryParse(filterItem.Value, out float filterValue); + _ = float.TryParse(filterItem.Value, out var filterValue); constantExpression = Expression.Constant((float?)filterValue); } else if (propertyTypeName == StringConstants.PropertyTypeNameDecimal) { - _ = decimal.TryParse(filterItem.Value, out decimal filterValue); + _ = decimal.TryParse(filterItem.Value, out var filterValue); constantExpression = Expression.Constant((decimal?)filterValue); } else if (propertyTypeName == StringConstants.PropertyTypeNameDouble) { - _ = double.TryParse(filterItem.Value, out double filterValue); + _ = double.TryParse(filterItem.Value, out var filterValue); constantExpression = Expression.Constant((double?)filterValue); } @@ -644,16 +605,16 @@ public static ConstantExpression GetDateConstantExpression(FilterItem filterItem if (filterItem.Value == null) return Expression.Constant(null); - ConstantExpression constantExpression = null; + ConstantExpression? constantExpression = null; if (propertyTypeName == StringConstants.PropertyTypeNameDateOnly) { - _ = DateOnly.TryParse(filterItem.Value, out DateOnly filterValue); + _ = DateOnly.TryParse(filterItem.Value, out var filterValue); constantExpression = Expression.Constant(filterValue); } else if (propertyTypeName == StringConstants.PropertyTypeNameDateTime) { - _ = DateTime.TryParse(filterItem.Value, out DateTime filterValue); + _ = DateTime.TryParse(filterItem.Value, out var filterValue); constantExpression = Expression.Constant(filterValue); } @@ -680,11 +641,11 @@ public static Expression> GetBooleanNotEqualExpressionDelegate public static ConstantExpression GetBooleanConstantExpression(FilterItem filterItem, string propertyTypeName) { - ConstantExpression value = null; + ConstantExpression? value = null; if (propertyTypeName == StringConstants.PropertyTypeNameBoolean) { - _ = bool.TryParse(filterItem.Value, out bool filterValue); + _ = bool.TryParse(filterItem.Value, out var filterValue); value = Expression.Constant(filterValue); } @@ -700,13 +661,5 @@ internal class SubstExpressionVisitor : ExpressionVisitor { public Dictionary subst = new(); - protected override Expression VisitParameter(ParameterExpression parameterExpression) - { - if (subst.TryGetValue(parameterExpression, out Expression newExpression)) - { - return newExpression; - } - - return parameterExpression; - } + protected override Expression VisitParameter(ParameterExpression parameterExpression) => subst.TryGetValue(parameterExpression, out var newExpression) ? newExpression : parameterExpression; } diff --git a/blazorbootstrap/Models/AutoCompleteDataProviderResult.cs b/blazorbootstrap/Models/AutoCompleteDataProviderResult.cs index de412ae75..90e0021aa 100644 --- a/blazorbootstrap/Models/AutoCompleteDataProviderResult.cs +++ b/blazorbootstrap/Models/AutoCompleteDataProviderResult.cs @@ -5,7 +5,7 @@ public class AutoCompleteDataProviderResult /// /// The provided items by the request. /// - public IEnumerable Data { get; init; } + public IEnumerable? Data { get; init; } /// /// The total item count in the source (for pagination and infinite scroll). diff --git a/blazorbootstrap/Models/BreadcrumbItem.cs b/blazorbootstrap/Models/BreadcrumbItem.cs index 4f9959782..b0675db15 100644 --- a/blazorbootstrap/Models/BreadcrumbItem.cs +++ b/blazorbootstrap/Models/BreadcrumbItem.cs @@ -2,9 +2,9 @@ public class BreadcrumbItem { - public string Text { get; set; } + public string? Text { get; set; } - public string Href { get; set; } + public string? Href { get; set; } /// /// Represents the current page. diff --git a/blazorbootstrap/Models/GridDataProviderResult.cs b/blazorbootstrap/Models/GridDataProviderResult.cs index e11e55c64..64046b5cd 100644 --- a/blazorbootstrap/Models/GridDataProviderResult.cs +++ b/blazorbootstrap/Models/GridDataProviderResult.cs @@ -5,7 +5,7 @@ public class GridDataProviderResult /// /// The provided items by the request. /// - public IEnumerable Data { get; init; } + public IEnumerable? Data { get; init; } /// /// The total item count in the source (for pagination and infinite scroll). diff --git a/blazorbootstrap/Models/NavItem.cs b/blazorbootstrap/Models/NavItem.cs index 595cc4054..a95ead7a7 100644 --- a/blazorbootstrap/Models/NavItem.cs +++ b/blazorbootstrap/Models/NavItem.cs @@ -7,14 +7,14 @@ public class NavItem /// /// Gets or sets the custom icon name. /// - public string CustomIconName { get; set; } + public string? CustomIconName { get; set; } internal bool HasChilds { get; set; } /// /// Gets or sets the href. /// - public string Href { get; set; } + public string? Href { get; set; } /// /// Gets or sets the icon color. @@ -29,7 +29,7 @@ public class NavItem /// /// Gets or sets the Id. /// - public string Id { get; set; } + public string? Id { get; set; } /// /// Gets or sets the URL matching behavior. @@ -39,7 +39,7 @@ public class NavItem /// /// Gets or sets the parent Id. /// - public string ParentId { get; set; } + public string? ParentId { get; set; } /// /// Gets or sets the sequence. @@ -54,5 +54,5 @@ public class NavItem /// /// Gets or sets the navigation link text. /// - public string Text { get; set; } + public string? Text { get; set; } } \ No newline at end of file diff --git a/blazorbootstrap/Models/SidebarDataProviderRequest.cs b/blazorbootstrap/Models/SidebarDataProviderRequest.cs index 6fc42d13a..df148bca3 100644 --- a/blazorbootstrap/Models/SidebarDataProviderRequest.cs +++ b/blazorbootstrap/Models/SidebarDataProviderRequest.cs @@ -7,7 +7,7 @@ public SidebarDataProviderResult ApplyTo(IEnumerable data) if (data is null) return new SidebarDataProviderResult { Data = Enumerable.Empty() }; - List result = new List(); + var result = new List(); var parentNavItems = data.Where(x => string.IsNullOrWhiteSpace(x.ParentId))?.OrderBy(x => x.Sequence); if (parentNavItems is null || !parentNavItems.Any()) diff --git a/blazorbootstrap/Models/SidebarDataProviderResult.cs b/blazorbootstrap/Models/SidebarDataProviderResult.cs index a05cb4c0a..ffa9171d8 100644 --- a/blazorbootstrap/Models/SidebarDataProviderResult.cs +++ b/blazorbootstrap/Models/SidebarDataProviderResult.cs @@ -5,5 +5,5 @@ public class SidebarDataProviderResult /// /// The provided items by the request. /// - public IEnumerable Data { get; init; } + public IEnumerable? Data { get; init; } } diff --git a/blazorbootstrap/Models/ToastMessage.cs b/blazorbootstrap/Models/ToastMessage.cs index eb9400c3c..df8358c09 100644 --- a/blazorbootstrap/Models/ToastMessage.cs +++ b/blazorbootstrap/Models/ToastMessage.cs @@ -25,80 +25,74 @@ public class ToastMessage : IEquatable public ToastMessage() { - this.Id = Guid.NewGuid(); + Id = Guid.NewGuid(); } public ToastMessage(ToastType type, string message) { - this.Id = Guid.NewGuid(); - this.Type = type; - this.Message = message; + Id = Guid.NewGuid(); + Type = type; + Message = message; } public ToastMessage(ToastType type, string title, string message) { - this.Id = Guid.NewGuid(); - this.Type = type; - this.Title = title; - this.Message = message; + Id = Guid.NewGuid(); + Type = type; + Title = title; + Message = message; } public ToastMessage(ToastType type, IconName iconName, string title, string message) { - this.Id = Guid.NewGuid(); - this.Type = type; - this.IconName = iconName; - this.Title = title; - this.Message = message; + Id = Guid.NewGuid(); + Type = type; + IconName = iconName; + Title = title; + Message = message; } public ToastMessage(ToastType type, string customIconName, string title, string message) { - this.Id = Guid.NewGuid(); - this.Type = type; - this.CustomIconName = customIconName; - this.Title = title; - this.Message = message; + Id = Guid.NewGuid(); + Type = type; + CustomIconName = customIconName; + Title = title; + Message = message; } public ToastMessage(ToastType type, IconName iconName, string title, string helpText, string message) { - this.Id = Guid.NewGuid(); - this.Type = type; - this.IconName = iconName; - this.Title = title; - this.HelpText = helpText; - this.Message = message; + Id = Guid.NewGuid(); + Type = type; + IconName = iconName; + Title = title; + HelpText = helpText; + Message = message; } public ToastMessage(ToastType type, string customIconName, string title, string helpText, string message) { - this.Id = Guid.NewGuid(); - this.Type = type; - this.CustomIconName = customIconName; - this.Title = title; - this.HelpText = helpText; - this.Message = message; + Id = Guid.NewGuid(); + Type = type; + CustomIconName = customIconName; + Title = title; + HelpText = helpText; + Message = message; } public ToastMessage(ToastType type, string customIconName, string title, string helpText, string message, bool autoHide) { - this.Id = Guid.NewGuid(); - this.Type = type; - this.CustomIconName = customIconName; - this.Title = title; - this.HelpText = helpText; - this.Message = message; - this.AutoHide = autoHide; + Id = Guid.NewGuid(); + Type = type; + CustomIconName = customIconName; + Title = title; + HelpText = helpText; + Message = message; + AutoHide = autoHide; } - internal void SetElementId(string elementId) => this.ElementId = elementId; + internal void SetElementId(string elementId) => ElementId = elementId; - public bool Equals(ToastMessage other) - { - if (other == null) - return false; - - return this.Id.Equals(other.Id); - } + public bool Equals(ToastMessage other) => other != null && Id.Equals(other.Id); }