当前位置: 首页>>代码示例>>C#>>正文


C# DOLEvent.IsValidFor方法代码示例

本文整理汇总了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();
				}
			}
		}
开发者ID:Refizul,项目名称:DOL-Kheldron,代码行数:73,代码来源:GameEventMgr.cs


注:本文中的DOL.Events.DOLEvent.IsValidFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。