You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SAE-2.01/MCTG/MCTGLib/Recipe.cs

86 lines
2.3 KiB

using System;
using System.Collections.Generic;
namespace MCTGLib
{
/// <summary>
/// A Recipe is a description of step and maybe some techniques, with an ingredient list to make a meal.<br/>
/// It is instantiated with a new unique id, where the first number is 1.
/// </summary>
public class Recipe : BaseItem
{
#region Private Attributes
private const int CAT_ITEM = 1;
private static uint _idCreator = 0; // stand for the creation of a new id. It is incremented each time a new Recipe is instantiated.
private string title = "";
#endregion
#region Public Properties
/// <summary>
/// The title of the recipe.
/// </summary>
public string Title
{
get => title;
set
{
title = value;
if (string.IsNullOrEmpty(title)) title = $"Recipe n{this.Id}";
}
}
/// <summary>
/// All the details about the preparation of the meal.
/// </summary>
public string Preparation { get; set; }
#endregion
#region Constructors
public Recipe(string title="", string preparation="")
: base(ComputeId(), "A recipe.")
{
Title = title;
Preparation = preparation;
}
#endregion
#region Private Methods
/// <summary>
/// Processi the unique identificator of an Item. The identificator is calculated to put the number representing
/// the type of item before the number of its number in its type.
/// </summary>
private static uint ComputeId()
{
uint dec = 1;
while ((_idCreator / (Math.Pow(10, dec)) >= 1)) dec++;
uint id = (CAT_ITEM * (uint)(Math.Pow(10, dec))) + _idCreator++;
Console.WriteLine("[recipe] new computed id: {0}", id);
return id;
}
#endregion
#region Public Methods
public override string ToString()
{
return
$"[ Class -Recipe- ]\n\n" +
$"\t.Id - {Id}\n" +
$"\t.Description - {Description}\n" +
$"______\n\n";
}
#endregion
}
}