本文整理汇总了C#中DOL.Events.DOLEvent.IsValidFor方法的典型用法代码示例。如果您正苦于以下问题:C# DOLEvent.IsValidFor方法的具体用法?C# DOLEvent.IsValidFor怎么用?C# DOLEvent.IsValidFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOL.Events.DOLEvent
的用法示例。
在下文中一共展示了DOLEvent.IsValidFor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddHandler
/// <summary>
/// Registers a single local event handler.
/// Local event handlers will only be called if the
/// "sender" parameter in the Notify method equals
/// the object for which a local event handler was
/// registered.
/// </summary>
/// <remarks>
/// Certain events will never have a local event handler.
/// This happens if the Notify method is called without
/// a sender parameter for example!
/// </remarks>
/// <param name="obj">The object that needs to be the sender of events</param>
/// <param name="e">The event type to register for</param>
/// <param name="del">The event handler to register for this event type</param>
/// <param name="unique">Flag wether event shall be added unique or not</param>
/// <exception cref="ArgumentNullException">If one of the parameters is null</exception>
private static void AddHandler(object obj, DOLEvent e, DOLEventHandler del, bool unique)
{
if(obj == null)
throw new ArgumentNullException("obj", "No object given!");
if(e == null)
throw new ArgumentNullException("e", "No event type given!");
if(del == null)
throw new ArgumentNullException("del", "No event handler given!");
if(!e.IsValidFor(obj))
throw new ArgumentException("Object is not valid for this event type", "obj");
if(Lock.TryEnterUpgradeableReadLock(LOCK_TIMEOUT))
{
try
{
DOLEventHandlerCollection col;
if(!m_gameObjectEventCollections.TryGetValue(obj, out col))
{
col = new DOLEventHandlerCollection();
if (Lock.TryEnterWriteLock(LOCK_TIMEOUT))
{
try
{
m_gameObjectEventCollections.Add(obj, col);
}
finally
{
Lock.ExitWriteLock();
}
}
else
{
log.ErrorFormat("Timeout exceeded on attempt to AddHandler for object: {0}, event: {1}", obj.ToString(), e.Name);
}
}
if(unique)
{
col.AddHandlerUnique(e, del);
}
else
{
col.AddHandler(e, del);
}
}
finally
{
Lock.ExitUpgradeableReadLock();
}
}
}