当前位置: 首页>>代码示例>>C#>>正文


C# MemberReferenceExpression.Resolve方法代码示例

本文整理汇总了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);
        }
开发者ID:JerreS,项目名称:AbstractCode,代码行数:12,代码来源:MemberResolutionTests.cs

示例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);
        }
开发者ID:JerreS,项目名称:AbstractCode,代码行数:19,代码来源:MemberResolutionTests.cs

示例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);
        }
开发者ID:JerreS,项目名称:AbstractCode,代码行数:20,代码来源:MemberResolutionTests.cs

示例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);
        }
开发者ID:JerreS,项目名称:AbstractCode,代码行数:19,代码来源:MemberResolutionTests.cs


注:本文中的MemberReferenceExpression.Resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。