Grammar.RuleName Property

Read-only value containing the name of root or entry point rule of a valid Grammar instance.

Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)

Syntax

'Declaration

Property Value

Returns a string with the name of root or entry point rule of a valid Grammar instance.

Remarks

If the root rule of a Grammar has no name, the method returns null.

The root rules of instances of Grammar constructed from GrammarBuilder objects typically have no name, so RuleName returns null.

Example

In the example below, a Windows.Forms.TreeView display of loaded Grammar object is updated with the grammar name (Name) and the root rule name (RuleName)

public void UpdateGrammarTree(TreeView grammarTreeView, SpeechRecognizer recognizer) {
    grammarTreeView.Nodes.Clear(); //clean up tree and repopulate
    foreach (Grammar grammar in recognizer.Grammars) {
        //Should probably do a sanity check and remove node if it exists.
        TreeNode grammarNode = new TreeNode(grammar.Name);
        grammarNode.Checked = grammar.Enabled;
        grammarNode.Tag = grammar;
        grammarNode.ForeColor = Color.Red;
        //Add rule name as next layer
        if (grammar.RuleName != null) {
            TreeNode ruleNode = new TreeNode(grammar.RuleName);
            ruleNode.Tag = grammar.RuleName;
            ruleNode.Checked = grammarNode.Checked;
            grammarNode.Nodes.Add(ruleNode);
        }
        grammarTreeView.Nodes.Add(grammarNode);
        grammarNode.ExpandAll();
    }
    grammarTreeView.ExpandAll();
    grammarTreeView.Show();
}

Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

See Also

Reference

Grammar Class
Grammar Members
Microsoft.Speech.Recognition Namespace