コード例 #1
0
        public override IEnumerable< XNode > Process(XNode node)
        {
            XElement element = _AssumeElement( node );
            string symbol_name = element.Name.LocalName;
            if ( !_Env.IsDefined( symbol_name ) )
                throw InvalidMarkupException.CreateException( "[{0}] Undefined symbol '{1}'   ",
                                                              node.ErrorContext(),
                                                              element.Name );
            /* Evaluate the symbol on a new stack frame, since we may be defining local symbols
             * based on the attributes */
            return _Env.Call( () =>
                                  {
                                      /* Bind attributes as local symbolic definitions */
                                      _DefineFromAttributes( element );
                                      /* Bind any nested definition elements */
                                      _ProcessNodes(
                                          element.Elements( _Env._Settings.Namespace.GetName("define") ).Select
                                              ( n => ( XNode ) n ) );

                                      // Must materialize the deferred-execution nodeset 
                                      // iterator before this method returns, otherwise 
                                      // the evaluation stack will be wrong.  Calling ToArray()
                                      // ensures this.
                                      return _Env.EvalSymbol( symbol_name ).ToArray();
                                      //return _ProcessNodes( ret );
                                  } );
        }
コード例 #2
0
 public override IEnumerable< XNode > Process(XNode node)
 {
     XElement element = _AssumeElement( node );
     // If "define" element has a "name" attribute, treat the element contents as a nodeset definition.
     if ( element.HasAttribute( AttrName.Name ) )
     {
         _Env.DefineNodesetSymbol( ( string ) element.Attribute( AttrName.Name ),
                                   element.Nodes() );
     }
         // ...otherwise treat each attribute as a separate text definition of the form "name=value"
     else if ( element.HasAttributes )
     {
         _DefineFromAttributes( element );
     }
     else
     {
         throw DefinitionException.CreateException(
             "{0} <define> element has no attributes.",
             node.ErrorContext() );
     }
     /* Define produces no output */
     return new XNode[] {};
 }
コード例 #3
0
ファイル: XHelpers.cs プロジェクト: kascomp/CruiseControl.NET
 private static string _ValueOf(XNode node)
 {
     switch (node.NodeType)
     {
         case XmlNodeType.Element:
             return ((XElement)node).Value;
         case XmlNodeType.Text:
             return ((XText)node).Value;
         case XmlNodeType.Comment:
         case XmlNodeType.ProcessingInstruction:
             return String.Empty;
         default:
             throw new InvalidOperationException(
                 string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0} Unhandled node type {1}",
                                node.ErrorContext(),
                                node.NodeType));
     }
 }