Ejemplo n.º 1
0
        public bool Equals(TaskDescription other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(Equals(other.Name, this.Name) &&
                   CollectionUtils.SequenceEqual(other.ParameterDescriptions, this.ParameterDescriptions) &&
                   Equals(other.IsDecorator, this.IsDecorator) && Equals(other.TypeName, this.TypeName) &&
                   Equals(other.ClassName, this.ClassName));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Generates a task description for the specified task type.
        /// </summary>
        /// <param name="taskType"> Task type. </param>
        /// <returns> Task description. </returns>
        public static TaskDescription Generate(Type taskType)
        {
            // Check for task attribute.
            TaskAttribute[] taskAttributes =
                taskType.GetCustomAttributes(typeof(TaskAttribute), true) as TaskAttribute[];
            if (taskAttributes == null || taskAttributes.Length == 0)
            {
                throw new ArgumentException(
                          "Type {0} doesn't have a task attribute which specifies the class as a behavior tree task.",
                          taskType.Name);
            }

            TaskAttribute taskAttribute = taskAttributes[0];

            TaskDescription description = new TaskDescription
            {
                Name                  = taskAttribute.Name,
                Description           = taskAttribute.Description,
                IsDecorator           = taskAttribute.IsDecorator,
                ClassName             = taskType.Name,
                TypeName              = taskType.AssemblyQualifiedName,
                ParameterDescriptions = new List <TaskParameterDescription>()
            };

            MemberInfo[] parameterMembers = taskType.GetMembers();
            foreach (MemberInfo parameterMember in parameterMembers)
            {
                TaskParameterDescription parameterDescription = TaskParameterDescription.Generate(parameterMember);
                if (parameterDescription == null)
                {
                    continue;
                }

                description.ParameterDescriptions.Add(parameterDescription);
            }

            return(description);
        }