SrgsDocument.Root 属性

定义

获取或设置 SrgsDocument 的根规则。Gets or sets the root rule of the SrgsDocument class.

public:
 property System::Speech::Recognition::SrgsGrammar::SrgsRule ^ Root { System::Speech::Recognition::SrgsGrammar::SrgsRule ^ get(); void set(System::Speech::Recognition::SrgsGrammar::SrgsRule ^ value); };
public System.Speech.Recognition.SrgsGrammar.SrgsRule Root { get; set; }
member this.Root : System.Speech.Recognition.SrgsGrammar.SrgsRule with get, set
Public Property Root As SrgsRule

属性值

SrgsRule

返回指定为 SrgsDocument 的根规则的规则。Returns the rule that is designated as the root rule of the SrgsDocument.

示例

下面的示例创建一个名为的规则 winnerRule ,然后创建一个 SrgsDocument 名为的对象 documentThe following example creates a rule named winnerRule, and then creates an SrgsDocument object named document. 然后,该示例调用 Add 方法将规则添加到文档中。The example then calls the Add method to add the rule to the document. 最后,该示例将文档的 Root 属性设置为 winnerRule ,从而使其成为 root rule 由对象定义的语法 SrgsDocumentFinally, the example sets the document's Root property to winnerRule, thereby making it the root rule for the grammar defined by the SrgsDocument object.

SrgsRule winnerRule = new SrgsRule("WorldCupWinner");  
winnerRule.Scope = SrgsRuleScope.Public;  

SrgsDocument document = new SrgsDocument();  

document.Rules.Add(winnerRule);  
document.Root = winnerRule;   

注解

SrgsRule SrgsRulesCollection 将对象设置为 根规则之前,该对象必须已在文档中。The SrgsRule object must already be in the document's SrgsRulesCollection before it can be set to the root rule.

还可以 SrgsDocument 通过使用 SrgsRule 对象作为构造函数的参数来设置对象的根规则 SrgsDocumentYou can also set the root rule for an SrgsDocument object by using an SrgsRule object as the argument to the SrgsDocument constructor.

适用于

另请参阅