728x90
반응형
728x170
■ IEditableObject 인터페이스를 사용하는 방법을 보여준다.
▶ PurchaseItem.cs
using System;
using System.ComponentModel;
/// <summary>
/// 구매 항목
/// </summary>
public class PurchaseItem : INotifyPropertyChanged, IEditableObject
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Event
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 속성 변경시 - PropertyChanged
/// <summary>
/// 속성 변경시
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Struct
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 항목 데이터 - ItemData
/// <summary>
/// 항목 데이터
/// </summary>
private struct ItemData
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Internal
#region Field
/// <summary>
/// 설명
/// </summary>
internal string Description;
/// <summary>
/// 제안 만기일
/// </summary>
internal DateTime OfferExpires;
/// <summary>
/// 가격
/// </summary>
internal double Price;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Internal
#region 새 항목 구하기 - GetNewItem()
/// <summary>
/// 새 항목 구하기
/// </summary>
/// <returns>새 항목</returns>
internal static ItemData GetNewItem()
{
ItemData data = new ItemData
{
Description = "New item",
Price = 0,
OfferExpires = DateTime.Now + new TimeSpan(7, 0, 0, 0)
};
return data;
}
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 복사 데이터
/// </summary>
private ItemData copyData = ItemData.GetNewItem();
/// <summary>
/// 현대 데이터
/// </summary>
private ItemData currentData = ItemData.GetNewItem();
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 설명 - Description
/// <summary>
/// 설명
/// </summary>
public string Description
{
get
{
return this.currentData.Description;
}
set
{
if(this.currentData.Description != value)
{
this.currentData.Description = value;
FirePropertyChangedEvent("Description");
}
}
}
#endregion
#region 가격 - Price
/// <summary>
/// 가격
/// </summary>
public double Price
{
get
{
return this.currentData.Price;
}
set
{
if(this.currentData.Price != value)
{
this.currentData.Price = value;
FirePropertyChangedEvent("Price");
}
}
}
#endregion
#region 제안 만기일 - OfferExpires
/// <summary>
/// 제안 만기일
/// </summary>
public DateTime OfferExpires
{
get
{
return this.currentData.OfferExpires;
}
set
{
if(value != this.currentData.OfferExpires)
{
this.currentData.OfferExpires = value;
FirePropertyChangedEvent("OfferExpires");
}
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - PurchaseItem()
/// <summary>
/// 생성자
/// </summary>
public PurchaseItem()
{
}
#endregion
#region 생성자 - PurchaseItem(description, price, offerExpires)
/// <summary>
/// 생성자
/// </summary>
/// <param name="description">설명</param>
/// <param name="price">가격</param>
/// <param name="offerExpires">제안 만기일</param>
public PurchaseItem(string description, double price, DateTime offerExpires)
{
Description = description;
Price = price;
OfferExpires = offerExpires;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 편집 시작하기 - BeginEdit()
/// <summary>
/// 편집 시작하기
/// </summary>
public void BeginEdit()
{
this.copyData = this.currentData;
}
#endregion
#region 편집 취소하기 - CancelEdit()
/// <summary>
/// 편집 취소하기
/// </summary>
public void CancelEdit()
{
this.currentData = this.copyData;
FirePropertyChangedEvent("");
}
#endregion
#region 편집 종료하기 - EndEdit()
/// <summary>
/// 편집 종료하기
/// </summary>
public void EndEdit()
{
this.copyData = ItemData.GetNewItem();
}
#endregion
#region 문자열 구하기 - ToString()
/// <summary>
/// 문자열 구하기
/// </summary>
/// <returns>문자열</returns>
public override string ToString() => $"{Description}, {Price:c}, {OfferExpires:D}";
#endregion
////////////////////////////////////////////////////////////////////////////////////////// Protected
#region 속성 변경시 이벤트 발생시키기 - FirePropertyChangedEvent(propertyName)
/// <summary>
/// 속성 변경시 이벤트 발생시키기
/// </summary>
/// <param name="propertyName">속성명</param>
private void FirePropertyChangedEvent(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 현재 네트워크 인터페이스의 MAC 주소 변경하기 (0) | 2023.02.21 |
---|---|
[C#/COMMON] NetworkInterface 클래스 : GetAllNetworkInterfaces 정적 메소드를 사용해 현재 네트워크 인터페이스 구하기 (0) | 2023.02.21 |
[C#/COMMON/.NET6] Random 클래스 : NextBytes 메소드를 사용해 임의 MAC 주소 구하기 (0) | 2023.02.21 |
[C#/COMMON] AesCryptoServiceProvider 클래스 : 암호화/복호화 사용하기 (0) | 2022.11.06 |
[C#/COMMON] RTF 파서 사용하기 (0) | 2022.11.03 |
[C#/COMMON/.NET6] Stream 클래스 : CopyTo 메소드를 사용해 스트림에서 바이트 배열 구하기 (0) | 2022.10.24 |
[C#/COMMON/.NET6] MemoryStream 클래스 : Write 메소드를 사용해 스트림에서 바이트 배열 구하기 (0) | 2022.10.24 |
[C#/COMMON/.NET6] DateTime 구조체 : ParseExact 정적 메소드를 사용해 ISO 8601 날짜 포맷 문자열에서 DateTime 객체 구하기 (0) | 2022.10.24 |
[C#/COMMON/.NET6] DateTime 구조체 : Parse 정적 메소드를 사용해 ISO 8601 날짜 포맷 문자열에서 DateTime 객체 구하기 (0) | 2022.10.24 |
[C#/COMMON/.NET6] Process 클래스 : 부모 프로세스 종료시 자식 프로세스 종료시키기 (0) | 2022.10.24 |
댓글을 달아 주세요