---
title: C# Example
encoding: utf-8
filter:
  - erb
  - maruku
---

<pre class="brush: csharp">
using System;
using System.Text.RegularExpressions;

namespace SharpVectors.Dom.Css
{
	/// &lt;summary>
	/// The CSSFontFaceRule interface represents a @font-face rule in a CSS style sheet. The @font-face rule is used to hold a set of font descriptions.
	/// &lt;/summary>
	/// &lt;developer>niklas@protocol7.com&lt;/developer>
	/// &lt;completed>80&lt;/completed>
	public class CssFontFaceRule : CssRule, ICssFontFaceRule
	{
		#region Static members
		private static Regex regex = new Regeх(@"^@font-face");
		
		/// &lt;summary>
		/// Parses a string containging CSS and creates a CssFontFaceRule instance if found as the first content
		/// &lt;/summary>
		internal static CssRule Parse(ref string css, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin)
		{
			Match match = regex.Match(css);
			if(match.Success)
			{
				CssFontFaceRule rule = new CssFontFaceRule(match, parent, readOnly, replacedStrings, origin);
				css = css.Substring(match.Length);

				rule.style = new CssStyleDeclaration(ref css, rule, true, origin);

				return rule;
			}
			else
			{
				// didn't match => do nothing
				return null;
			}
		}
		#endregion

		#region Constructors
		/// &lt;summary>
		/// The constructor for CssFontFaceRule
		/// &lt;/summary>
		/// &lt;param name="match">The Regex match that found the charset rule&lt;/param>
		/// &lt;param name="parent">The parent rule or parent stylesheet&lt;/param>
		/// &lt;param name="readOnly">True if this instance is readonly&lt;/param>
		/// &lt;param name="replacedStrings">An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method&lt;/param>
		/// &lt;param name="origin">The type of CssStyleSheet&lt;/param>
		internal CssFontFaceRule(Match match, object parent, bool readOnly, string[] replacedStrings, CssStyleSheetType origin) : base(parent, true, replacedStrings, origin)
		{
			// always read-only
			
		}
		#endregion

		#region Implementation of ICssFontFaceRule
		private CssStyleDeclaration style;
		/// &lt;summary>
		/// The declaration-block of this rule.
		/// &lt;/summary>
		public ICssStyleDeclaration Style
		{
			get
			{
				return style;
			}
		}
		#endregion

		#region Implementation of ICssRule
		/// &lt;summary>
		/// The type of the rule. The expectation is that binding-specific casting methods can be used to cast down from an instance of the CSSRule interface to the specific derived interface implied by the type.
		/// &lt;/summary>
		public override CssRuleType Type
		{
			get
			{
				return CssRuleType.FontFaceRule;
			}
		}
		#endregion
	}
}
</pre> 

<%= render(:partial => "/SyntaxHighlighter/partials/brushes") %> 

 
