Exemplo n.º 1
0
        /// <summary>
        /// Writes this task to an XML writer, using the given parameters object.
        /// </summary>
        /// <param name="Writer">Writer for the XML schema</param>
        /// <param name="Parameters">Parameters object that this task is constructed with</param>
        protected void Write(XmlWriter Writer, object Parameters)
        {
            TaskElementAttribute Element = GetType().GetCustomAttribute <TaskElementAttribute>();

            Writer.WriteStartElement(Element.Name);

            foreach (FieldInfo Field in Parameters.GetType().GetFields())
            {
                if (Field.MemberType == MemberTypes.Field)
                {
                    TaskParameterAttribute ParameterAttribute = Field.GetCustomAttribute <TaskParameterAttribute>();
                    if (ParameterAttribute != null)
                    {
                        object Value = Field.GetValue(Parameters);
                        if (Value != null && Field.FieldType == typeof(bool) && (bool)Value == false)
                        {
                            Value = null;
                        }
                        if (Value != null)
                        {
                            Writer.WriteAttributeString(Field.Name, Value.ToString());
                        }
                    }
                }
            }

            Writer.WriteEndElement();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="InName">Name of the task</param>
        /// <param name="InTaskClass">Task class to create</param>
        /// <param name="InParametersClass">Class type of an object to be constructed and passed as an argument to the task class constructor</param>
        public ScriptTask(string InName, Type InTaskClass, Type InParametersClass)
        {
            Name            = InName;
            TaskClass       = InTaskClass;
            ParametersClass = InParametersClass;

            // Find all the fields which are tagged as parameters in ParametersClass
            foreach (FieldInfo Field in ParametersClass.GetFields())
            {
                if (Field.MemberType == MemberTypes.Field)
                {
                    TaskParameterAttribute ParameterAttribute = Field.GetCustomAttribute <TaskParameterAttribute>();
                    if (ParameterAttribute != null)
                    {
                        NameToParameter.Add(Field.Name, new ScriptTaskParameter(Field.Name, Field, ParameterAttribute.ValidationType, ParameterAttribute.Optional));
                    }
                }
            }
        }