Пример #1
0
        /// <summary>
        /// Find a condition interface that contains the specified method and return it.
        /// </summary>
        /// <param name="methodName"></param>
        /// <param name="conditionInterfaces"></param>
        /// <param name="agent"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T AddConditionInterface <T>(string methodName, ref List <T> conditionInterfaces, Agent agent) where T : ConditionInterface
        {
            var obj       = AgentFunctions.GetTypeByMethodName <T>(methodName);
            var className = obj.ToString();

            if (conditionInterfaces == null)
            {
                conditionInterfaces = new List <T>();
            }
            if (conditionInterfaces.Count > 0)
            {
                for (int i = 0; i < conditionInterfaces.Count; i++)
                {
                    if (conditionInterfaces[i].GetType().ToString() == className)
                    {
                        return(conditionInterfaces[i]);
                    }
                }
            }
            var type = System.Type.GetType(className);

            var ctor = type.GetConstructor(new[] { typeof(Agent) });
            var conditionInterface = ctor.Invoke(new object[] { agent }) as T;

            conditionInterfaces.Add(conditionInterface);
            return(conditionInterface);
        }
Пример #2
0
 public InventoryConditionInterface AddConditionInterface(string methodName)
 {
     return(AgentFunctions.AddConditionInterface(methodName, ref _conditionInterfaces, _agent));
 }