Praeclarum.HtmlRichText.AddAttributes C# (CSharp) Method

AddAttributes() public method

public AddAttributes ( IRichTextAttributes styleClass, StringRange range ) : void
styleClass IRichTextAttributes
range StringRange
return void
		public void AddAttributes (IRichTextAttributes styleClass, StringRange range)
		{
			if (range.Length == 0)
				return;

			var starts = spans [range.Location];

			//
			// If there already an identical span
			//
			Span span = null;
			if (starts != null) {
				foreach (var s in starts) {
					if (s.Range.Length == range.Length) {
						span = s;
						break;
					}
				}
				if (span != null) {
					span.AddClass (styleClass.ClassName);
					return;
				}
			}

			//
			// If not, we need to insert it
			//
			span = new Span (range, styleClass.ClassName);
			span.Url = styleClass.Link;
			if (starts == null) {
				starts = new List<Span> ();
				spans [range.Location] = starts;
				starts.Add (span);
				return;
			}

			//
			// Insert it before shorter spans
			//
			var i = 0;
			while (i < starts.Count && starts [i].Range.Length >= range.Length) {
				i++;
			}
			starts.Insert (i, span);
		}
	}