Beispiel #1
0
		public static object GetProperty(behaviac.Agent agent, string property)
		{
			Type type = agent.GetType();
			string propertyName = type.FullName + property;
			if (_fields.ContainsKey(propertyName))
			{
				return _fields[propertyName].GetValue(agent);
			}

			if (_properties.ContainsKey(propertyName))
			{
				return _properties[propertyName].GetValue(agent, null);
			}

			while (type != typeof(object))
			{
				FieldInfo field = type.GetField(property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
				if (field != null)
				{
					_fields[propertyName] = field;
					return field.GetValue(agent);
				}

				PropertyInfo prop = type.GetProperty(property, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
				if (prop != null)
				{
					_properties[propertyName] = prop;
					return prop.GetValue(agent, null);
				}

				type = type.BaseType;
			}
			Debug.Check(false, "No property can be found!");
			return null;
		}
        public static object ExecuteMethod(behaviac.Agent agent, string method, object[] args)
        {
            Type type = agent.GetType();
            string methodName = type.FullName + method;
            if (_methods.ContainsKey(methodName))
            {
                return _methods[methodName].Invoke(agent, args);;
            }

            while (type != typeof(object))
            {
                MethodInfo m = type.GetMethod(method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                if (m != null)
                {
                    _methods[methodName] = m;
                    return m.Invoke(agent, args);
                }

                type = type.BaseType;
            }
            Debug.Check(false, "No method can be found!");
            return null;
        }