Esempio n. 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);
        }
Esempio n. 2
0
        public static object GetProperty(Agent agent, string property)
        {
            Type   baseType = agent.GetType();
            string key      = baseType.FullName + property;

            if (_fields.ContainsKey(key))
            {
                return(_fields[key].GetValue(agent));
            }
            if (_properties.ContainsKey(key))
            {
                return(_properties[key].GetValue(agent, null));
            }
            while (baseType != typeof(object))
            {
                FieldInfo field = baseType.GetField(property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (field != null)
                {
                    _fields[key] = field;
                    return(field.GetValue(agent));
                }
                PropertyInfo info2 = baseType.GetProperty(property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (info2 != null)
                {
                    _properties[key] = info2;
                    return(info2.GetValue(agent, null));
                }
                baseType = baseType.BaseType;
            }
            return(null);
        }
Esempio n. 3
0
        public static void SetProperty(Agent agent, string property, object value)
        {
            Type   baseType = agent.GetType();
            string key      = baseType.FullName + property;

            if (_fields.ContainsKey(key))
            {
                _fields[key].SetValue(agent, value);
            }
            else if (_properties.ContainsKey(key))
            {
                _properties[key].SetValue(agent, value, null);
            }
            else
            {
                while (baseType != typeof(object))
                {
                    FieldInfo field = baseType.GetField(property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                    if (field != null)
                    {
                        _fields[key] = field;
                        field.SetValue(agent, value);
                        return;
                    }
                    PropertyInfo info2 = baseType.GetProperty(property, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                    if (info2 != null)
                    {
                        _properties[key] = info2;
                        info2.SetValue(agent, value, null);
                        return;
                    }
                    baseType = baseType.BaseType;
                }
            }
        }
Esempio n. 4
0
        public static void SetProperty(Agent agent, string property, object value)
        {
            Type   type = agent.GetType();
            string text = type.get_FullName() + property;

            if (AgentExtra_Generated._fields.ContainsKey(text))
            {
                AgentExtra_Generated._fields.get_Item(text).SetValue(agent, value);
                return;
            }
            if (AgentExtra_Generated._properties.ContainsKey(text))
            {
                AgentExtra_Generated._properties.get_Item(text).SetValue(agent, value, null);
                return;
            }
            while (type != typeof(object))
            {
                FieldInfo field = type.GetField(property, 60);
                if (field != null)
                {
                    AgentExtra_Generated._fields.set_Item(text, field);
                    field.SetValue(agent, value);
                    return;
                }
                PropertyInfo property2 = type.GetProperty(property, 60);
                if (property2 != null)
                {
                    AgentExtra_Generated._properties.set_Item(text, property2);
                    property2.SetValue(agent, value, null);
                    return;
                }
                type = type.get_BaseType();
            }
        }
Esempio n. 5
0
 public static bool IsDerived(Agent pAgent, string agentType)
 {
     for (System.Type type = pAgent.GetType(); type != null; type = type.BaseType)
     {
         if (type.FullName == agentType)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 6
0
        public static bool IsDerived(Agent pAgent, string agentType)
        {
            bool result = false;

            for (Type type = pAgent.GetType(); type != null; type = type.get_BaseType())
            {
                if (type.get_FullName() == agentType)
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
Esempio n. 7
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);
 }
Esempio n. 8
0
        public static object ExecuteMethod(Agent agent, string method, object[] args)
        {
            Type   baseType = agent.GetType();
            string key      = baseType.FullName + method;

            if (_methods.ContainsKey(key))
            {
                return(_methods[key].Invoke(agent, args));
            }
            while (baseType != typeof(object))
            {
                MethodInfo info = baseType.GetMethod(method, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
                if (info != null)
                {
                    _methods[key] = info;
                    return(info.Invoke(agent, args));
                }
                baseType = baseType.BaseType;
            }
            return(null);
        }
Esempio n. 9
0
        public static object ExecuteMethod(Agent agent, string method, object[] args)
        {
            Type   type = agent.GetType();
            string text = type.get_FullName() + method;

            if (AgentExtra_Generated._methods.ContainsKey(text))
            {
                return(AgentExtra_Generated._methods.get_Item(text).Invoke(agent, args));
            }
            while (type != typeof(object))
            {
                MethodInfo method2 = type.GetMethod(method, 60);
                if (method2 != null)
                {
                    AgentExtra_Generated._methods.set_Item(text, method2);
                    return(method2.Invoke(agent, args));
                }
                type = type.get_BaseType();
            }
            return(null);
        }