APISampleUnitTestsCS.FAQ.GetFullyQualifiedName C# (CSharp) Метод

GetFullyQualifiedName() приватный Метод

private GetFullyQualifiedName ( ) : void
Результат void
        public void GetFullyQualifiedName()
        {
            var source = @"
            using System;
            using Alias=NS.C<int>;
            namespace NS
            {
            public class C<T>
            {
            public struct S<U>
            {
            }
            }
            }
            class Program
            {
            public static void Main()
            {
            Alias.S<long> s = new Alias.S<long>(); Console.WriteLine(s.ToString());
            }
            }";
            var solutionId = SolutionId.CreateNewId();
            ProjectId projectId;
            DocumentId documentId;
            var solution = Solution.Create(solutionId)
                .AddCSharpProject("MyProject", "MyProject", out projectId)
                .AddMetadataReference(projectId, MetadataReference.CreateAssemblyReference("mscorlib"))
                .AddDocument(projectId, "MyFile.cs", source, out documentId);
            var document = solution.GetDocument(documentId);
            var root = document.GetSyntaxRoot();
            var model = (SemanticModel)document.GetSemanticModel();

            // Get StructDeclarationSyntax corresponding to 'struct S' above.
            StructDeclarationSyntax structDeclaration = root.DescendantNodes()
                .OfType<StructDeclarationSyntax>().Single();

            // Get TypeSymbol corresponding to 'struct S' above.
            TypeSymbol structType = model.GetDeclaredSymbol(structDeclaration);

            // Use ToDisplayString() to get fully qualified name.
            Assert.AreEqual("NS.C<T>.S<U>", structType.ToDisplayString());
            Assert.AreEqual("global::NS.C<T>.S<U>", structType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));

            // Get VariableDeclaratorSyntax corresponding to 'Alias.S<long> s = ...' above.
            VariableDeclaratorSyntax variableDeclarator = root.DescendantNodes()
                .OfType<VariableDeclaratorSyntax>().Single();

            // Get TypeSymbol corresponding to above VariableDeclaratorSyntax.
            TypeSymbol variableType = ((LocalSymbol)model.GetDeclaredSymbol(variableDeclarator)).Type;

            Assert.IsFalse(variableType.Equals(structType)); // Type of variable is a closed generic type while that of the struct is an open generic type.
            Assert.IsTrue(variableType.OriginalDefinition.Equals(structType)); // OriginalDefinition for a closed generic type points to corresponding open generic type.
            Assert.AreEqual("NS.C<int>.S<long>", variableType.ToDisplayString());
            Assert.AreEqual("global::NS.C<int>.S<long>", variableType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
        }