#region Apache Notice
/*****************************************************************************
* $Revision: 476843 $
* $LastChangedDate$
* $LastChangedBy$
*
* iBATIS.NET Data Mapper
* Copyright (C) 2008/2005 - The Apache Software Foundation
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
********************************************************************************/
#endregion
using System;
using System.ComponentModel;
using Apache.Ibatis.DataMapper.Model.Events;
namespace Apache.Ibatis.DataMapper.Model.ResultMapping
{
///
/// Base implementation for
///
[Serializable]
public abstract class ResultPropertyEventSupport : IResultPropertySupportEvents
{
protected static readonly object PrePropertyEvent = new object();
protected static readonly object PostPropertyEvent = new object();
private readonly EventHandlerList events = new EventHandlerList();
#region IResultPropertySupportEvents Members
///
/// Handles event generated before setting the property value in an instance of a object.
///
public event EventHandler PreProperty
{
add { events.AddHandler(PrePropertyEvent, value); }
remove { events.RemoveHandler(PrePropertyEvent, value); }
}
///
/// Handles event generated after setting the property value in an instance of a object.
///
public event EventHandler PostProperty
{
add { events.AddHandler(PostPropertyEvent, value); }
remove { events.RemoveHandler(PostPropertyEvent, value); }
}
#endregion
///
/// Raises the .
///
/// The target.
/// The value.
/// Returns is used as databse value, to be set on the property
protected object RaisePrePropertyEvent(object target, object value)
{
EventHandler handlers = (EventHandler)events[PrePropertyEvent];
if (handlers != null)
{
PrePropertyEventArgs evnt = new PrePropertyEventArgs();
evnt.DataBaseValue = value;
evnt.Target = target;
handlers(this, evnt);
return evnt.DataBaseValue;
}
return value;
}
///
/// Raises the .
///
/// The target.
protected void RaisePostPropertyEvent(object target)
{
EventHandler handlers = (EventHandler)events[PostPropertyEvent];
if (handlers != null)
{
PostPropertyEventArgs evnt = new PostPropertyEventArgs();
evnt.Target = target;
handlers(this, evnt);
}
}
}
}