コード例 #1
0
 public void AddItemEffectHandler(ItemEffectHandler handler)
 {
     System.Type type = handler.GetType();
     if (type.GetCustomAttribute <DefaultEffectHandlerAttribute>() != null)
     {
         throw new System.Exception("Default handler cannot be added");
     }
     EffectHandlerAttribute[] array = type.GetCustomAttributes <EffectHandlerAttribute>().ToArray <EffectHandlerAttribute>();
     if (array.Length == 0)
     {
         throw new System.Exception(string.Format("EffectHandler '{0}' has no EffectHandlerAttribute", type.Name));
     }
     System.Reflection.ConstructorInfo constructor = type.GetConstructor(new System.Type[]
     {
         typeof(EffectBase),
         typeof(Character),
         typeof(BasePlayerItem)
     });
     if (constructor == null)
     {
         throw new System.Exception("No valid constructors found !");
     }
     foreach (EffectsEnum current in
              from entry in array
              select entry.Effect)
     {
         this.m_itemsEffectHandler.Add(current, constructor.CreateDelegate <EffectManager.ItemEffectConstructor>());
         if (!this.m_effectsHandlers.ContainsKey(current))
         {
             this.m_effectsHandlers.Add(current, new System.Collections.Generic.List <System.Type>());
         }
         this.m_effectsHandlers[current].Add(type);
     }
 }
コード例 #2
0
ファイル: EffectManager.cs プロジェクト: Mixi59/Stump
        public void AddItemEffectHandler(ItemEffectHandler handler)
        {
            var type = handler.GetType();

            if (type.GetCustomAttribute <DefaultEffectHandlerAttribute>() != null)
            {
                throw new Exception("Default handler cannot be added");
            }

            var attributes = type.GetCustomAttributes <EffectHandlerAttribute>().ToArray();

            if (attributes.Length == 0)
            {
                throw new Exception(string.Format("EffectHandler '{0}' has no EffectHandlerAttribute", type.Name));
            }

            var ctor = type.GetConstructor(new[] { typeof(EffectBase), typeof(Character), typeof(BasePlayerItem) });

            if (ctor == null)
            {
                throw new Exception("No valid constructors found !");
            }

            foreach (var effect in attributes.Select(entry => entry.Effect))
            {
                m_itemsEffectHandler.Add(effect, ctor.CreateDelegate <ItemEffectConstructor>());

                if (!m_effectsHandlers.ContainsKey(effect))
                {
                    m_effectsHandlers.Add(effect, new List <Type>());
                }

                m_effectsHandlers[effect].Add(type);
            }
        }