Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ public string Name
get { return name; }
set
{
ProductEventArgs args = new ProductEventArgs(name, value);
name = value;
/*
* TODO #4 Инициировать уведомление об
* изменении наименования
*/
if (NameChanged != null)
NameChanged(this, args);
}
}
/// <summary>
Expand All @@ -47,11 +50,14 @@ public decimal Price
get { return price; }
set
{
price = value;
/*
* TODO #5 Инициировать уведомление об
* изменении стоимости
*/
ProductEventArgs args = new ProductEventArgs(price, value);
price = value;
if (PriceChanged != null)
PriceChanged(this, args);
}
}

Expand All @@ -62,6 +68,8 @@ public decimal Price
/*
* TODO #3 Добавить определение событий
*/
public event EventHandler<ProductEventArgs> NameChanged;
public event EventHandler<ProductEventArgs> PriceChanged;

#endregion

Expand Down
18 changes: 17 additions & 1 deletion ProductEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,27 @@
/*
* TODO #1 Закончить определение класса ProductEventArgs
*/
class ProductEventArgs
class ProductEventArgs : EventArgs
{
/*
* TODO #2 Добавить определение необходимых компонент
* класса ProductEventArgs
*/
public string Prev_Name { get; }
public string New_Name { get; }
public decimal Prev_Price { get; }
public decimal New_Price { get; }

public ProductEventArgs(string prev_Name, string new_Name)
{
Prev_Name = prev_Name;
New_Name = new_Name;
}

public ProductEventArgs(decimal prev_Price, decimal new_Price)
{
Prev_Price = prev_Price;
New_Price = new_Price;
}
}
}
17 changes: 17 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,33 @@ static void Main(string[] args)
/*
* TODO #6 Назначить обработчики событий в текущем контексте
*/
product.NameChanged += ProductNameChanged;
product.PriceChanged += ProductPriceChanged;

/*
* TODO #7 Выполнить с экземпляром класса Product действия,
* приводящие к возникновению описанных Вами событий
*/
product.Name = "Product1";
product.Name = "NewProduct";
product.Price = 5677;
product.Price = 678;
}

/*
* TODO #8 Добавить определение обработчиков событий
*/
private static void ProductNameChanged(object sender, ProductEventArgs e)
{
Product product = sender as Product;
Console.WriteLine("Name of {0} has changed to {1}", e.Prev_Name, e.New_Name);
}

private static void ProductPriceChanged(object sender, ProductEventArgs e)
{
Product product = sender as Product;
Console.WriteLine("Price has changed from {0} to {1}", e.Prev_Price, e.New_Price);
}

}
}