public JNode VisitMemberReferenceExpression(MemberReferenceExpression node) { var res = node.Resolve(); if (res.Type.Kind == TypeKind.Dynamic) { return(VisitExpression(node.Target).Member(node.MemberName)); } return(Visit(res)); }
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); }
public JsNode VisitMemberReferenceExpression(MemberReferenceExpression node) { var res = node.Resolve(); // The following is block uncommented because: See issue 352 //if (res.Type.Kind == TypeKind.Dynamic) //{ // return VisitExpression(node.Target).Member(node.MemberName); //} return(Visit(res)); }
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); }
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); }
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); }