Пример #1
0
        /**
         * bind 'agentInstanceName' to 'pAgentInstance'.
         * 'agentInstanceName' should have been registered to the class of 'pAgentInstance' or its parent class.
         *
         * @sa RegisterName
         */
        public bool BindInstance(Agent pAgentInstance, string agentInstanceName)
        {
            if (string.IsNullOrEmpty(agentInstanceName))
            {
                agentInstanceName = pAgentInstance.GetType().FullName;
            }

            if (Agent.IsNameRegistered(agentInstanceName))
            {
                Debug.Check(GetInstance(agentInstanceName) == null, "the name has been bound to an instance already!");

                string className = Agent.GetRegisteredClassName(agentInstanceName);

                if (Agent.IsDerived(pAgentInstance, className))
                {
                    m_namedAgents[agentInstanceName] = pAgentInstance;

                    return(true);
                }
            }
            else
            {
                Debug.Check(false);
            }

            return(false);
        }
Пример #2
0
 public bool BindInstance(Agent pAgentInstance, string agentInstanceName)
 {
     if (string.IsNullOrEmpty(agentInstanceName))
     {
         agentInstanceName = pAgentInstance.GetType().get_FullName();
     }
     if (Agent.IsNameRegistered(agentInstanceName))
     {
         string registeredClassName = Agent.GetRegisteredClassName(agentInstanceName);
         if (Agent.IsDerived(pAgentInstance, registeredClassName))
         {
             this.m_namedAgents.set_Item(agentInstanceName, pAgentInstance);
             return(true);
         }
     }
     return(false);
 }