Implementing IEditableObject when using as a datasource
If have used a class as datasource , you would know that to provide proper validation and you would nees to implement a IEditableObject, but if you sont its really simple all you have to do is provide 3 functions , The code Mentioned below is a simple example and I think you can take it from there
public class ReceiptPay : IEditableObject { public int FeeComponentId { get; set; } public string FeeComponent { get; set; } public decimal Amount { get; set; } private decimal amtbkp; private bool inTXN = false; public ReceiptPay(int FCId, string FC) { FeeComponentId = FCId; FeeComponent = FC; } #region IEditableObject Members public void BeginEdit() { if (!inTXN) { amtbkp = Amount; inTXN = true; } } public void CancelEdit() { if (inTXN) { Amount = amtbkp; inTXN = false; } } public void EndEdit() { inTXN = false; } #endregion }
I believe your sample is an overly-simplified example. When you call beginedit and canceledit for example, you only backup and restore the Amount property. This could be misleading to a new developer as in reality you would (usually) want all of your properties backed up.
Practical advice for anyone considering implementing IEditableObject for your custom Business Object class, create a struct inside your class, and inside of that store all of your actual data. Then, keep 2 instances of your struct inside the class, one as your backup, and one within which to perform your operations. This is also a good opportunity to run a validation check, should your object support it.
Outside of the struct, you would need public Get/Set accessors for each property, which would be a useful thing should you also wish to implement INotifyPropertyChanged.
Walt is right in the sense that my example is very basic in nature, i will update with the proper solution in a few days,