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
20 changes: 9 additions & 11 deletions Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ public string Name
get { return name; }
set
{
var args = new ProductEventArgs(name, value, price, price);
name = value;
/*
* TODO #4 Инициировать уведомление об
* изменении наименования
*/
/*TODO #4 Инициировать уведомление об изменении наименования*/
NameChanged?.Invoke(this, args);
}
}
/// <summary>
Expand All @@ -47,21 +46,20 @@ public decimal Price
get { return price; }
set
{
var args = new ProductEventArgs(name, name, price, value);
price = value;
/*
* TODO #5 Инициировать уведомление об
* изменении стоимости
*/
/*TODO #5 Инициировать уведомление об изменении стоимости*/
PriceChanged?.Invoke(this, args);
}
}

#endregion

#region Events

/*
* TODO #3 Добавить определение событий
*/
/*TODO #3 Добавить определение событий*/
public event EventHandler<ProductEventArgs> NameChanged;
public event EventHandler<ProductEventArgs> PriceChanged;

#endregion

Expand Down
28 changes: 18 additions & 10 deletions ProductEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
namespace Events
{
using System;

namespace Events
{
/// <summary>
/// Класс, который служит для передачи аргументов
/// в обработчик событий, возникающих в классе
/// <seealso cref="Product">Product</seealso>
/// </summary>
/*
* TODO #1 Закончить определение класса ProductEventArgs
*/
class ProductEventArgs
/*TODO #1 Закончить определение класса 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; }
/* TODO #2 Добавить определение необходимых компонент класса ProductEventArgs*/
public ProductEventArgs(string prev_Name, string new_Name, decimal prev_Price, decimal new_Price)
{
Prev_Name = prev_Name;
New_Name = new_Name;
Prev_Price = prev_Price;
New_Price = new_Price;
}
}
}
80 changes: 43 additions & 37 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
namespace Events
{
class Program
{
internal Product Product
{
get
{
throw new System.NotImplementedException();
}

set
{
throw new System.NotImplementedException();
}
}

static void Main(string[] args)
{
Product product = new Product("Some product name", 0);

/*
* TODO #6 Назначить обработчики событий в текущем контексте
*/

/*
* TODO #7 Выполнить с экземпляром класса Product действия,
* приводящие к возникновению описанных Вами событий
*/
}

/*
* TODO #8 Добавить определение обработчиков событий
*/

}
}
using System;

namespace Events
{
class Program
{
internal Product Product
{
get
{
throw new System.NotImplementedException();
}

set
{
throw new System.NotImplementedException();
}
}

static void Main(string[] args)
{
Product product = new Product("Some product name", 0);

/*TODO #6 Назначить обработчики событий в текущем контексте*/
product.NameChanged += OnNameChanged;
product.PriceChanged += OnPriceChanged;
/*TODO #7 Выполнить с экземпляром класса Product действия, приводящие к возникновению описанных Вами событий*/
product.Price = 999;
product.Name = "Cake";
Console.ReadKey();
}

/*TODO #8 Добавить определение обработчиков событий*/
private static void OnPriceChanged(object addresser, ProductEventArgs args)
{
Console.WriteLine("Price has been changed from {0} to {1}!", args.Prev_Price, args.New_Price);
}
private static void OnNameChanged(object addresser, ProductEventArgs args)
{
Console.WriteLine("Name has been changed from {0} to {1}!", args.Prev_Name, args.New_Name);
}
}
}