本文整理汇总了C#中Program.SetMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# Program.SetMetadata方法的具体用法?C# Program.SetMetadata怎么用?C# Program.SetMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Program
的用法示例。
在下文中一共展示了Program.SetMetadata方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WholeProgram
public void WholeProgram() {
var p = new Program();
var t = new TypedIdent(Token.NoToken, "foo", Microsoft.Boogie.Type.Bool);
var gv = new GlobalVariable(Token.NoToken, t);
p.AddTopLevelDeclaration(gv);
string metaDataString = "This is a test";
p.SetMetadata(0, metaDataString);
// Now try to clone
var p2 = (Program) d.Visit(p);
// Check global is a copy
int counter = 0;
GlobalVariable gv2 = null;
foreach (var g in p2.TopLevelDeclarations)
{
++counter;
Assert.IsInstanceOf<GlobalVariable>(g);
gv2 = g as GlobalVariable;
}
Assert.AreEqual(1, counter);
Assert.AreNotSame(gv, gv2);
Assert.AreEqual(metaDataString, p2.GetMetadata<string>(0));
// Check Top level declarations list is duplicated properly
var t2 = new TypedIdent(Token.NoToken, "bar", Microsoft.Boogie.Type.Bool);
var gv3 = new GlobalVariable(Token.NoToken, t2);
p2.AddTopLevelDeclaration(gv3);
counter = 0;
foreach (var g in p2.TopLevelDeclarations) {
++counter;
Assert.IsInstanceOf<GlobalVariable>(g);
}
Assert.AreEqual(2, counter);
// The original program should still only have one global variable
counter = 0;
foreach (var g in p.TopLevelDeclarations) {
++counter;
Assert.IsInstanceOf<GlobalVariable>(g);
Assert.AreSame(g, gv);
}
Assert.AreEqual(1, counter);
// Change Metadata in p2, this shouldn't affect p
string newMetaDataString = "Another test";
p2.SetMetadata(0, newMetaDataString);
Assert.AreNotEqual(p2.GetMetadata<string>(0), p.GetMetadata<string>(0));
}