提交 2166857b 编写于 作者: T Ty Overby 提交者: GitHub

add test for symbol on result of typeof (#14209)

add test for symbol on result of typeof
上级 3d6d280b
......@@ -138,6 +138,7 @@
<Compile Include="Semantics\SyntaxTreeRootTests.cs" />
<Compile Include="Semantics\SynthesizedStaticConstructorTests.cs" />
<Compile Include="Semantics\TryCatchTests.cs" />
<Compile Include="Semantics\TypeOfTests.cs" />
<Compile Include="Semantics\UnsafeTests.cs" />
<Compile Include="Semantics\UserDefinedConversionTests.cs" />
<Compile Include="Semantics\UseSiteErrorTests.cs" />
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
using System.Linq;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public class TypeofTests : CSharpTestBase
{
[Fact, WorkItem(1720, "https://github.com/dotnet/roslyn/issues/1720")]
public void GetSymbolsOnResultOfTypeof()
{
var source = @"
class C
{
public C(int i)
{
typeof(C).GetField("" "").SetValue(null, new C(0));
}
}
";
var compilation = CreateCompilationWithMscorlib45(source);
var tree = compilation.SyntaxTrees[0];
var model = compilation.GetSemanticModel(tree);
var node = (ObjectCreationExpressionSyntax) tree.GetRoot().DescendantNodes().Where(n => n.ToString() == "new C(0)").Last();
var identifierName = node.Type;
var symbolInfo = model.GetSymbolInfo(node);
Assert.Equal("C..ctor(System.Int32 i)", symbolInfo.Symbol.ToTestDisplayString());
var typeInfo = model.GetTypeInfo(node);
Assert.Equal("C", typeInfo.Type.ToTestDisplayString());
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册