本文整理汇总了C#中TypeDeclaration.GetScope方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDeclaration.GetScope方法的具体用法?C# TypeDeclaration.GetScope怎么用?C# TypeDeclaration.GetScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeDeclaration
的用法示例。
在下文中一共展示了TypeDeclaration.GetScope方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LookupMemberInSameClass
public void LookupMemberInSameClass()
{
var type = new TypeDeclaration("MyType", TypeVariant.Class);
type.Members.Add(new FieldDeclaration("MyField", new PrimitiveTypeReference(PrimitiveType.String)));
_compilationUnit.Types.Add(type);
var result = new IdentifierExpression("MyField").Resolve(type.GetScope());
Assert.IsInstanceOfType(result, typeof(MemberResolveResult));
var memberResult = (MemberResolveResult)result;
Assert.AreEqual("MyField", memberResult.Member.Name);
Assert.AreEqual("System.String", memberResult.Member.MemberType.FullName);
}
示例2: LookupMemberInSameNamespace
public void LookupMemberInSameNamespace()
{
var type1 = new TypeDeclaration("MyType1", TypeVariant.Class);
type1.Members.Add(new FieldDeclaration("MyField", new PrimitiveTypeReference(PrimitiveType.String))
{
ModifierElements = { new ModifierElement(Modifier.Public), new ModifierElement(Modifier.Static) }
});
var type2 = new TypeDeclaration("MyType2", TypeVariant.Class);
var @namespace = new NamespaceDeclaration("MyNamespace") { Types = { type1, type2 } };
_compilationUnit.Namespaces.Add(@namespace);
var referenceExpression = new MemberReferenceExpression(new IdentifierExpression("MyType1"), "MyField");
var result = referenceExpression.Resolve(type2.GetScope());
Assert.IsInstanceOfType(result, typeof(MemberResolveResult));
var memberResult = (MemberResolveResult)result;
Assert.AreEqual("MyNamespace.MyType1::MyField", memberResult.Member.FullName);
Assert.AreEqual("System.String", memberResult.Member.MemberType.FullName);
}