Exemplo n.º 1
0
 private static bool IsEventUsedInField(Type fieldType, object fieldValue, string eventName)
 {
     if (fieldValue == null)
     {
         return(false);
     }
     if (fieldType == typeof(SkillEvent))
     {
         SkillEvent fsmEvent = (SkillEvent)fieldValue;
         return(eventName == fsmEvent.get_Name());
     }
     if (fieldType.get_IsArray())
     {
         Array array       = (Array)fieldValue;
         Type  elementType = fieldType.GetElementType();
         if (elementType == typeof(SkillEvent))
         {
             for (int i = 0; i < array.get_Length(); i++)
             {
                 if (SkillInfo.IsEventUsedInField(elementType, array.GetValue(i), eventName))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        private static IEnumerable <SkillInfo> FindEventUsage(object obj, string eventName)
        {
            List <SkillInfo> list = new List <SkillInfo>();

            if (obj != null)
            {
                Type        type   = obj.GetType();
                FieldInfo[] fields = type.GetFields(20);
                FieldInfo[] array  = fields;
                for (int i = 0; i < array.Length; i++)
                {
                    FieldInfo fieldInfo = array[i];
                    Type      fieldType = fieldInfo.get_FieldType();
                    object    value     = fieldInfo.GetValue(obj);
                    if (fieldType == typeof(SkillEventTarget))
                    {
                        SkillInfo.currentEventTarget = (value as SkillEventTarget);
                    }
                    if (SkillInfo.IsEventUsedInField(fieldType, value, eventName))
                    {
                        list.Add(new SkillInfo(SkillInfo.currentInfo)
                        {
                            field       = fieldInfo,
                            eventTarget = SkillInfo.currentEventTarget
                        });
                    }
                    else
                    {
                        if (fieldType.get_IsClass())
                        {
                            list.AddRange(SkillInfo.FindEventUsage(value, eventName));
                        }
                    }
                }
            }
            return(list);
        }