PageRenderTime 21ms CodeModel.GetById 2ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlTag.cs

http://github.com/icsharpcode/ILSpy
C# | 108 lines | 73 code | 13 blank | 22 comment | 23 complexity | 926be9803610a61c57d1bf5554a99ab6 MD5 | raw file
  1// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
  3
  4using System;
  5using System.Collections.Generic;
  6using System.Collections.ObjectModel;
  7using System.Collections.Specialized;
  8using System.Diagnostics;
  9using System.Globalization;
 10using System.Linq;
 11
 12using ICSharpCode.AvalonEdit.Document;
 13
 14namespace ICSharpCode.AvalonEdit.Xml
 15{
 16	/// <summary>
 17	/// Represents any markup starting with "&lt;" and (hopefully) ending with ">"
 18	/// </summary>
 19	public class AXmlTag: AXmlContainer
 20	{
 21		/// <summary> These identify the start of DTD elements </summary>
 22		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification="ReadOnlyCollection is immutable")]
 23		public static readonly ReadOnlyCollection<string> DtdNames = new ReadOnlyCollection<string>(
 24			new string[] {"<!DOCTYPE", "<!NOTATION", "<!ELEMENT", "<!ATTLIST", "<!ENTITY" } );
 25		
 26		/// <summary> Opening bracket - usually "&lt;" </summary>
 27		public string OpeningBracket { get; internal set; }
 28		/// <summary> Name following the opening bracket </summary>
 29		public string Name { get; internal set; }
 30		/// <summary> Opening bracket - usually "&gt;" </summary>
 31		public string ClosingBracket { get; internal set; }
 32		
 33		/// <summary> True if tag starts with "&lt;" </summary>
 34		public bool IsStartOrEmptyTag       { get { return OpeningBracket == "<"; } }
 35		/// <summary> True if tag starts with "&lt;" and ends with "&gt;" </summary>
 36		public bool IsStartTag              { get { return OpeningBracket == "<" && ClosingBracket == ">"; } }
 37		/// <summary> True if tag starts with "&lt;" and does not end with "&gt;" </summary>
 38		public bool IsEmptyTag              { get { return OpeningBracket == "<" && ClosingBracket != ">" ; } }
 39		/// <summary> True if tag starts with "&lt;/" </summary>
 40		public bool IsEndTag                { get { return OpeningBracket == "</"; } }
 41		/// <summary> True if tag starts with "&lt;?" </summary>
 42		public bool IsProcessingInstruction { get { return OpeningBracket == "<?"; } }
 43		/// <summary> True if tag starts with "&lt;!--" </summary>
 44		public bool IsComment               { get { return OpeningBracket == "<!--"; } }
 45		/// <summary> True if tag starts with "&lt;![CDATA[" </summary>
 46		public bool IsCData                 { get { return OpeningBracket == "<![CDATA["; } }
 47		/// <summary> True if tag starts with one of the DTD starts </summary>
 48		public bool IsDocumentType          { get { return DtdNames.Contains(OpeningBracket); } }
 49		/// <summary> True if tag starts with "&lt;!" </summary>
 50		public bool IsUnknownBang           { get { return OpeningBracket == "<!"; } }
 51		
 52		#region Helpper methods
 53		
 54		AXmlAttributeCollection attributes;
 55		
 56		/// <summary> Gets attributes of the tag (if applicable) </summary>
 57		public AXmlAttributeCollection Attributes {
 58			get {
 59				if (attributes == null) {
 60					attributes = new AXmlAttributeCollection(this.Children);
 61				}
 62				return attributes;
 63			}
 64		}
 65		
 66		#endregion
 67		
 68		internal override void DebugCheckConsistency(bool checkParentPointers)
 69		{
 70			Assert(OpeningBracket != null, "Null OpeningBracket");
 71			Assert(Name != null, "Null Name");
 72			Assert(ClosingBracket != null, "Null ClosingBracket");
 73			base.DebugCheckConsistency(checkParentPointers);
 74		}
 75		
 76		/// <inheritdoc/>
 77		public override void AcceptVisitor(IAXmlVisitor visitor)
 78		{
 79			visitor.VisitTag(this);
 80		}
 81		
 82		/// <inheritdoc/>
 83		internal override bool UpdateDataFrom(AXmlObject source)
 84		{
 85			if (!base.UpdateDataFrom(source)) return false;
 86			AXmlTag src = (AXmlTag)source;
 87			if (this.OpeningBracket != src.OpeningBracket ||
 88				this.Name != src.Name ||
 89				this.ClosingBracket != src.ClosingBracket)
 90			{
 91				OnChanging();
 92				this.OpeningBracket = src.OpeningBracket;
 93				this.Name = src.Name;
 94				this.ClosingBracket = src.ClosingBracket;
 95				OnChanged();
 96				return true;
 97			} else {
 98				return false;
 99			}
100		}
101		
102		/// <inheritdoc/>
103		public override string ToString()
104		{
105			return string.Format(CultureInfo.InvariantCulture, "[{0} '{1}{2}{3}' Attr:{4}]", base.ToString(), this.OpeningBracket, this.Name, this.ClosingBracket, this.Children.Count);
106		}
107	}
108}