|
#region Header
/* --------------------------------------------------------------------------------------------------------------
* I Software Innovations
* --------------------------------------------------------------------------------------------------------------
* SVG Artieste 2.0
* --------------------------------------------------------------------------------------------------------------
* File : PropertyChangeCommand.cs
* Author : ajaysbritto@yahoo.com
* Date : 20/03/2010
* --------------------------------------------------------------------------------------------------------------
* Change Log
* --------------------------------------------------------------------------------------------------------------
* Author Comments
*/
#endregion Header
namespace Draw.Command
{
using System;
using System.Collections;
using System.Reflection;
using System.Windows.Forms;
class PropertyChangeCommand : ICommand
{
#region Fields
private readonly ArrayList _itemsWhosePropertyChanged;
private readonly Object _oldProperty;
private readonly GridItem _propertyWhichChanged;
private Object _newProperty;
#endregion Fields
#region Constructors
public PropertyChangeCommand(ArrayList itemsWhosePropertyChanged,
GridItem propertyWhichChanged,
Object oldProperty)
{
_itemsWhosePropertyChanged = new ArrayList();
_itemsWhosePropertyChanged.AddRange(itemsWhosePropertyChanged);
_itemsWhosePropertyChanged = itemsWhosePropertyChanged;
_propertyWhichChanged = propertyWhichChanged;
_oldProperty = oldProperty;
}
//Disable default constructor
private PropertyChangeCommand()
{
}
#endregion Constructors
#region Methods
public void Execute()
{
try
{
for (int i = 0; i < _itemsWhosePropertyChanged.Count; i++)
{
Type t = _itemsWhosePropertyChanged[i].GetType();
if (_propertyWhichChanged != null)
{
PropertyInfo pi = t.GetProperty(_propertyWhichChanged.Label);
pi.SetValue(_itemsWhosePropertyChanged[i], _newProperty, null);
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void UnExecute()
{
try
{
for (int i = 0; i < _itemsWhosePropertyChanged.Count; i++)
{
Type t = _itemsWhosePropertyChanged[i].GetType();
if (_propertyWhichChanged != null)
{
PropertyInfo pi = t.GetProperty(_propertyWhichChanged.Label);
_newProperty = pi.GetValue(_itemsWhosePropertyChanged[i], null);
pi.SetValue(_itemsWhosePropertyChanged[i], _oldProperty, null);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion Methods
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
He is a Microsoft technology enthusiast, who wish to create applications which others find useful.He loves making small tools and getting involved in architecting bigger systems.
He is currently working as a professional developer in a software development firm in .Net technologies.
He likes reading technical blogs, contributing to opensource and most importantly, enjoying life.
His ambition is to be an impressive software maker.