本文整理汇总了C#中MemberReferenceExpression.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# MemberReferenceExpression.Resolve方法的具体用法?C# MemberReferenceExpression.Resolve怎么用?C# MemberReferenceExpression.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemberReferenceExpression
的用法示例。
在下文中一共展示了MemberReferenceExpression.Resolve方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LookupAmbiguousMemberInOtherAssembly
public void LookupAmbiguousMemberInOtherAssembly()
{
_compilationUnit.UsingDirectives.Add(new UsingNamespaceDirective("System"));
var reference = new MemberReferenceExpression(new IdentifierExpression("Console"), "WriteLine");
var result = reference.Resolve(_compilationUnit.GetScope());
Assert.IsInstanceOfType(result, typeof(AmbiguousMemberResolveResult));
var memberResult = (AmbiguousMemberResolveResult)result;
Assert.AreEqual("System.Console", memberResult.Member.DeclaringType.FullName);
Assert.AreEqual("WriteLine", memberResult.Member.Name);
Assert.IsTrue(memberResult.Candidates.Count > 1);
}
示例2: LookupArrayTypeMember
public void LookupArrayTypeMember()
{
_compilationUnit.UsingDirectives.Add(new UsingNamespaceDirective("System"));
var reference = new MemberReferenceExpression
{
Target = new ParenthesizedExpression(
new CreateArrayExpression(
new PrimitiveTypeReference(PrimitiveType.Byte),
new PrimitiveExpression(3))),
Identifier = new Identifier("Length")
};
var result = reference.Resolve(_compilationUnit.GetScope());
Assert.IsInstanceOfType(result, typeof(MemberResolveResult));
var memberResult = (MemberResolveResult)result;
Assert.AreEqual("System.Array", memberResult.Member.DeclaringType.FullName);
Assert.AreEqual("Length", memberResult.Member.Name);
Assert.AreEqual("System.Int32", memberResult.Member.MemberType.FullName);
}
示例3: LookupPointerTypeMember
public void LookupPointerTypeMember()
{
_compilationUnit.UsingDirectives.Add(new UsingNamespaceDirective("System"));
var reference = new MemberReferenceExpression
{
Target = new ParenthesizedExpression(
new ExplicitCastExpression(
new PointerTypeReference(new SimpleTypeReference("String")),
new PrimitiveExpression(null))),
Accessor = MemberAccessor.Pointer,
Identifier = new Identifier("Length")
};
var result = reference.Resolve(_compilationUnit.GetScope());
Assert.IsInstanceOfType(result, typeof(MemberResolveResult));
var memberResult = (MemberResolveResult)result;
Assert.AreEqual("System.String", memberResult.Member.DeclaringType.FullName);
Assert.AreEqual("Length", memberResult.Member.Name);
Assert.AreEqual("System.Int32", memberResult.Member.MemberType.FullName);
}
示例4: 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);
}