本文整理汇总了C#中Scope.DefineIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C# Scope.DefineIdentifier方法的具体用法?C# Scope.DefineIdentifier怎么用?C# Scope.DefineIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scope
的用法示例。
在下文中一共展示了Scope.DefineIdentifier方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NestedScopesCanStillFindLocallyDefinedIdentifier
public void NestedScopesCanStillFindLocallyDefinedIdentifier()
{
var scope = new Scope();
var identifier = "A";
scope.DefineIdentifier(identifier, new Value(1));
using (scope.PushScope())
{
scope.DefineIdentifier(identifier, new Value(2));
var actual = scope.FindIdentifier(identifier);
Assert.AreEqual(true, actual.IsDefined);
}
}
示例2: PopScopeDefinesANewMoreDeeplyNestedScope
public void PopScopeDefinesANewMoreDeeplyNestedScope()
{
var scope = new Scope();
var identifier = "A";
var expected = 1234;
scope.DefineIdentifier(identifier, new Value(expected));
scope.PushScope();
scope.DefineIdentifier(identifier, new Value(1));
scope.PopScope();
var actual = scope.FindIdentifier(identifier);
Assert.AreEqual(expected, actual.Value.ToObject());
}
示例3: DefinedIdentifiersAreAbleToBeFound
public void DefinedIdentifiersAreAbleToBeFound()
{
var scope = new Scope();
scope.DefineIdentifier("TEST", new Value(1));
var actual = scope.FindIdentifier("TEST");
Assert.AreEqual(true, actual.IsDefined);
}
示例4: PushScopeReturnsAnIDisposableWhichPopsScopeAutomatically
public void PushScopeReturnsAnIDisposableWhichPopsScopeAutomatically()
{
var scope = new Scope();
var identifier = "A";
var expected = 1234;
scope.DefineIdentifier(identifier, new Value(expected));
using (scope.PushScope())
{
scope.DefineIdentifier(identifier, new Value(1));
}
var actual = scope.FindIdentifier(identifier);
Assert.AreEqual(expected, actual.Value.ToObject());
}
示例5: DucplicateIdentifiersAtTheSameLevelAreDisallowed
public void DucplicateIdentifiersAtTheSameLevelAreDisallowed()
{
var scope = new Scope();
var identifier = "A";
scope.DefineIdentifier(identifier, new Value(1));
scope.DefineIdentifier(identifier, new Value(1));
}
示例6: PushArgumentsIsAShortWayToAddIdentifiersIntoANewScopeQuickly
public void PushArgumentsIsAShortWayToAddIdentifiersIntoANewScopeQuickly()
{
var scope = new Scope();
// colliding identifier in parent scpoe
scope.DefineIdentifier("A", new Value(1345645));
var arguments = new[]
{
new VarDefinitionStmt(new IdentifierExpr("A"), new IdentifierExpr("int"), false, new ConstantExpr(1)),
new VarDefinitionStmt(new IdentifierExpr("B"), new IdentifierExpr("string"), false, new ConstantExpr("hello")),
new VarDefinitionStmt(new IdentifierExpr("C"), new IdentifierExpr("bool"), false, new ConstantExpr(true))
};
var values = new Value[]
{
new Value(2),
new Value("world"),
new Value(false)
};
using (scope.PushArguments(arguments, values))
{
for (var i = 0; i < arguments.Length; i++)
{
var argument = arguments[i];
var value = values[i];
var actual = scope.FindIdentifier(argument.Name.Name);
Assert.AreEqual(true, actual.IsDefined);
Assert.AreEqual(value.ToObject(), actual.Value.ToObject());
}
}
}
示例7: NestedScopesReturnsIdentifierFromAncestorIfNotFoundLocally
public void NestedScopesReturnsIdentifierFromAncestorIfNotFoundLocally()
{
var scope = new Scope();
var identifier = "A";
var expected = 2;
scope.DefineIdentifier(identifier, new Value(expected));
using (scope.PushScope())
{
scope.DefineIdentifier("B", new Value(3));
using (scope.PushScope())
{
scope.DefineIdentifier("C", new Value(4));
using (scope.PushScope())
{
scope.DefineIdentifier("D", new Value(5));
using (scope.PushScope())
{
scope.DefineIdentifier("E", new Value(6));
{
scope.DefineIdentifier("F", new Value(7));
var actual = scope.FindIdentifier(identifier);
Assert.AreEqual(expected, actual.Value.ToObject());
}
}
}
}
}
}
示例8: NestedScopesReturnsTheMostDeeplyDefinedInstanceOfAnIdentifier
public void NestedScopesReturnsTheMostDeeplyDefinedInstanceOfAnIdentifier()
{
var scope = new Scope();
var identifier = "A";
var expected = 2;
scope.DefineIdentifier(identifier, new Value(1));
using (scope.PushScope())
{
scope.DefineIdentifier(identifier, new Value(expected));
var actual = scope.FindIdentifier(identifier);
Assert.AreEqual(expected, actual.Value.ToObject());
}
}