This documentation is archived and is not being maintained.

SrgsRule.Add Method

Adds an SRGS element to a rule.

Namespace: System.Speech.Recognition.SrgsGrammar
Assembly: System.Speech (in system.speech.dll)

public void Add (
	SrgsElement element
public void Add (
	SrgsElement element
public function Add (
	element : SrgsElement
Not applicable.



Text or other XML elements that specify what speakers can say, and the order in which they can say it. A valid rule element must contain at least one piece of recognizable text or one rule reference.

Exception typeCondition


element is a null reference (Nothing in Visual Basic).

The following example creates an inline grammar with a single SrgsRule element and adds an SrgsOneOf element to the Elements property of the SrgsRule element. The SrgsOneOf element consists of SrgsItem elements containing alternatives to be recognized by the rule.

/// <summary>
/// Create an inline grammar
/// </summary>
/// <param name="mode">recognition mode: dtmf or voice</param>
protected void CreateInlineGrammar(SrgsGrammarMode mode)
  SrgsDocument grammar1 = new SrgsDocument();
  grammar1.Culture = Thread.CurrentThread.CurrentUICulture;
  grammar1.Mode = mode;

  //rule name is language independent 
  SrgsRule rule1 = new SrgsRule("rootRule");
  grammar1.Root = rule1;

  ResourceInfo resources = TaskletHost.Resources;

  SrgsOneOf ListOfAlternatives = new SrgsOneOf();

  if (resources.GrammarTexts != null)
    foreach (string alternative in resources.GrammarTexts)
      ListOfAlternatives.Add(new SrgsItem(alternative));
  inlineGrammar = new Grammar(grammar1);


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0