Added XMLDoc where needed
This commit is contained in:
parent
cc027f15af
commit
f8ffe9c7aa
3 changed files with 82 additions and 0 deletions
|
|
@ -5,12 +5,22 @@ public sealed class Food : Product
|
||||||
private const char AllergenSeparator = '|';
|
private const char AllergenSeparator = '|';
|
||||||
private readonly SortedSet<AllergenType> _allergens;
|
private readonly SortedSet<AllergenType> _allergens;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The constructor of Food
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productName">The product name</param>
|
||||||
|
/// <param name="barcode">The bar code</param>
|
||||||
|
/// <param name="quantity">The quantity</param>
|
||||||
|
/// <param name="allergens">The allergens</param>
|
||||||
public Food(string productName, string barcode, int quantity, params AllergenType[] allergens)
|
public Food(string productName, string barcode, int quantity, params AllergenType[] allergens)
|
||||||
: base(productName, barcode, quantity)
|
: base(productName, barcode, quantity)
|
||||||
{
|
{
|
||||||
_allergens = new SortedSet<AllergenType>(allergens);
|
_allergens = new SortedSet<AllergenType>(allergens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The allergens
|
||||||
|
/// </summary>
|
||||||
public AllergenType[] Allergens => _allergens.ToArray();
|
public AllergenType[] Allergens => _allergens.ToArray();
|
||||||
|
|
||||||
protected override string[] CsvColumnNames => ["Barcode", "ProductName", "Quantity", "Allergens"];
|
protected override string[] CsvColumnNames => ["Barcode", "ProductName", "Quantity", "Allergens"];
|
||||||
|
|
@ -24,6 +34,11 @@ public sealed class Food : Product
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds an allergen
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="allergen">The allergen to add</param>
|
||||||
|
/// <returns>True if the allergen was successfully added, false otherwise</returns>
|
||||||
public bool AddAllergen(AllergenType allergen)
|
public bool AddAllergen(AllergenType allergen)
|
||||||
{
|
{
|
||||||
if (ContainsAnyAllergen(allergen))
|
if (ContainsAnyAllergen(allergen))
|
||||||
|
|
@ -35,8 +50,18 @@ public sealed class Food : Product
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes an allergen
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="allergen">The allergen to remove</param>
|
||||||
|
/// <returns>True if the allergen was successfully removed, false otherwise</returns>
|
||||||
public bool RemoveAllergen(AllergenType allergen) => _allergens.Remove(allergen);
|
public bool RemoveAllergen(AllergenType allergen) => _allergens.Remove(allergen);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the food contains any of the given allergens
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="allergens">The allergens to check</param>
|
||||||
|
/// <returns>True if any of the allergens are contained, false otherwise</returns>
|
||||||
public bool ContainsAnyAllergen(params AllergenType[] allergens)
|
public bool ContainsAnyAllergen(params AllergenType[] allergens)
|
||||||
{
|
{
|
||||||
foreach (var allergen in allergens)
|
foreach (var allergen in allergens)
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,14 @@ public sealed class NonFood : Product
|
||||||
_reviews = new List<Review>();
|
_reviews = new List<Review>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The list of reviews
|
||||||
|
/// </summary>
|
||||||
public Review[] Reviews => _reviews.ToArray();
|
public Review[] Reviews => _reviews.ToArray();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The average rating
|
||||||
|
/// </summary>
|
||||||
public double? AverageRating
|
public double? AverageRating
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -36,6 +42,10 @@ public sealed class NonFood : Product
|
||||||
AverageRating?.ToString("F1", CultureInfo.InvariantCulture) ?? String.Empty
|
AverageRating?.ToString("F1", CultureInfo.InvariantCulture) ?? String.Empty
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a review
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="review">The review to add</param>
|
||||||
public void AddReview(Review review)
|
public void AddReview(Review review)
|
||||||
{
|
{
|
||||||
_reviews.Add(review);
|
_reviews.Add(review);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,12 @@ public abstract class Product
|
||||||
|
|
||||||
public const string Invalid = "Invalid!";
|
public const string Invalid = "Invalid!";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The constructor of Product
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="productName">The product name</param>
|
||||||
|
/// <param name="barcode">The bar code</param>
|
||||||
|
/// <param name="quantity">The quantity</param>
|
||||||
protected Product(string productName, string barcode, int quantity)
|
protected Product(string productName, string barcode, int quantity)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(productName))
|
if (string.IsNullOrWhiteSpace(productName))
|
||||||
|
|
@ -17,22 +23,56 @@ public abstract class Product
|
||||||
Quantity = quantity > 0 ? quantity : 0;
|
Quantity = quantity > 0 ? quantity : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The product name
|
||||||
|
/// </summary>
|
||||||
public string ProductName { get; }
|
public string ProductName { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The bar code of the product
|
||||||
|
/// </summary>
|
||||||
public string Barcode { get; }
|
public string Barcode { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The quantity of the product
|
||||||
|
/// </summary>
|
||||||
public int Quantity { get; }
|
public int Quantity { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The CSV column names
|
||||||
|
/// </summary>
|
||||||
protected virtual string[] CsvColumnNames => [nameof(Barcode), nameof(ProductName), nameof(Quantity)];
|
protected virtual string[] CsvColumnNames => [nameof(Barcode), nameof(ProductName), nameof(Quantity)];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The CSV column values
|
||||||
|
/// </summary>
|
||||||
protected virtual string[] CsvColumnValues => [Barcode, ProductName, Quantity.ToString()];
|
protected virtual string[] CsvColumnValues => [Barcode, ProductName, Quantity.ToString()];
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The CSV header
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The formatted CSV header</returns>
|
||||||
public string GetCsvHeader() => string.Join(Separator, CsvColumnNames);
|
public string GetCsvHeader() => string.Join(Separator, CsvColumnNames);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The CSV line
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The formatted CSV line with values</returns>
|
||||||
public string ToCsv() => ToCsvLine(CsvColumnValues, Separator);
|
public string ToCsv() => ToCsvLine(CsvColumnValues, Separator);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The CSV line generator
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="values">The values</param>
|
||||||
|
/// <param name="separator">The separator</param>
|
||||||
|
/// <returns>The formatted CSV line</returns>
|
||||||
protected static string ToCsvLine(string[] values, char separator) => String.Join(separator, values);
|
protected static string ToCsvLine(string[] values, char separator) => String.Join(separator, values);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if the bar code is valid
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="barcode">The bar code to check</param>
|
||||||
|
/// <returns>True if the bar code is valid, false otherwise</returns>
|
||||||
public static bool IsBarcodeValid(string? barcode)
|
public static bool IsBarcodeValid(string? barcode)
|
||||||
{
|
{
|
||||||
if (barcode == null)
|
if (barcode == null)
|
||||||
|
|
@ -75,6 +115,13 @@ public abstract class Product
|
||||||
return calculatedCheckDigit == int.Parse(barcode[^1].ToString());
|
return calculatedCheckDigit == int.Parse(barcode[^1].ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Appends new values to an existing array
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="existingArray">The array to append to</param>
|
||||||
|
/// <param name="newValues">The array of values to append</param>
|
||||||
|
/// <typeparam name="T">The type</typeparam>
|
||||||
|
/// <returns>The complete array</returns>
|
||||||
protected static T[] AppendToArray<T>(T[] existingArray, params T[] newValues)
|
protected static T[] AppendToArray<T>(T[] existingArray, params T[] newValues)
|
||||||
{
|
{
|
||||||
// we are allowed to use Lists, so why not? :)
|
// we are allowed to use Lists, so why not? :)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue