コード例 #1
0
 /// <summary>
 /// Read an include directive, and the contents of the target file
 /// </summary>
 /// <param name="Element">Xml element to read the definition from</param>
 /// <param name="BaseDir">Base directory to resolve relative include paths from </param>
 void ReadInclude(ScriptElement Element, DirectoryReference BaseDir)
 {
     if (EvaluateCondition(Element))
     {
         FileReference Script = FileReference.Combine(BaseDir, Element.GetAttribute("Script"));
         if (Script.Exists())
         {
             TryRead(Script);
         }
         else
         {
             LogError(Element, "Cannot find included script '{0}'", Script.FullName);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Evaluates the (optional) conditional expression on a given XML element via the If="..." attribute, and returns true if the element is enabled.
        /// </summary>
        /// <param name="Element">The element to check</param>
        /// <returns>True if the element's condition evaluates to true (or doesn't have a conditional expression), false otherwise</returns>
        bool EvaluateCondition(ScriptElement Element)
        {
            // Check if the element has a conditional attribute
            const string AttributeName = "If";

            if (!Element.HasAttribute(AttributeName))
            {
                return(true);
            }

            // If it does, try to evaluate it.
            try
            {
                string Text = ExpandProperties(Element.GetAttribute("If"));
                return(Condition.Evaluate(Text));
            }
            catch (ConditionException Ex)
            {
                LogError(Element, "Error in condition: {0}", Ex.Message);
                return(false);
            }
        }
コード例 #3
0
 /// <summary>
 /// Expands any properties and reads an attribute.
 /// </summary>
 /// <param name="Element">Element to read the attribute from</param>
 /// <param name="Name">Name of the attribute</param>
 /// <returns>Array of names, with all leading and trailing whitespace removed</returns>
 string ReadAttribute(ScriptElement Element, string Name)
 {
     return(ExpandProperties(Element.GetAttribute(Name)));
 }