The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.XsltOld \ Avt

  1. //------------------------------------------------------------------------------
  2. // <copyright file="Avt.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Xml.Xsl.XsltOld
  16. {
  17.     using Res = System.Xml.Utils.Res;
  18.     using System;
  19.     using System.Diagnostics;
  20.     using System.Collections;
  21.     using System.Xml;
  22.     using System.Xml.XPath;
  23.     using System.Text;
  24.    
  25.     internal sealed class Avt
  26.     {
  27.         private string constAvt;
  28.         private TextEvent[] events;
  29.        
  30.         private Avt(string constAvt)
  31.         {
  32.             Debug.Assert(constAvt != null);
  33.             this.constAvt = constAvt;
  34.         }
  35.        
  36.         private Avt(ArrayList eventList)
  37.         {
  38.             Debug.Assert(eventList != null);
  39.             this.events = new TextEvent[eventList.Count];
  40.             for (int i = 0; i < eventList.Count; i++) {
  41.                 this.events[i] = (TextEvent)eventList[i];
  42.             }
  43.         }
  44.        
  45.         public bool IsConstant {
  46.             get { return this.events == null; }
  47.         }
  48.        
  49.         internal string Evaluate(Processor processor, ActionFrame frame)
  50.         {
  51.             if (IsConstant) {
  52.                 Debug.Assert(constAvt != null);
  53.                 return constAvt;
  54.             }
  55.             else {
  56.                 Debug.Assert(processor != null && frame != null);
  57.                
  58.                 StringBuilder builder = processor.GetSharedStringBuilder();
  59.                
  60.                 for (int i = 0; i < events.Length; i++) {
  61.                     builder.Append(events[i].Evaluate(processor, frame));
  62.                 }
  63.                 processor.ReleaseSharedStringBuilder();
  64.                 return builder.ToString();
  65.             }
  66.         }
  67.        
  68.         static internal Avt CompileAvt(Compiler compiler, string avtText)
  69.         {
  70.             Debug.Assert(compiler != null);
  71.             Debug.Assert(avtText != null);
  72.            
  73.             bool constant;
  74.             ArrayList list = compiler.CompileAvt(avtText, out constant);
  75.             return constant ? new Avt(avtText) : new Avt(list);
  76.         }
  77.     }
  78. }

Developer Fusion