Exemple #1
0
 /// <summary>
 /// Gets a value that indicates if <paramref name="targetTypeInfo"/> is represented using
 /// <paramref name="sourceTypeSymbol"/> in the symbol graph.
 /// </summary>
 /// <param name="sourceTypeSymbol">The <see cref="ITypeSymbol"/>.</param>
 /// <param name="targetTypeInfo">The <see cref="System.Reflection.TypeInfo"/>.</param>
 /// <returns><c>true</c> if <paramref name="targetTypeInfo"/> is a symbol for
 /// <paramref name="sourceTypeSymbol"/>.</returns>
 public static bool IsType(
     ITypeSymbol sourceTypeSymbol,
     System.Reflection.TypeInfo targetTypeInfo)
 {
     return(string.Equals(
                RuntimeTypeInfo.SanitizeFullName(targetTypeInfo.FullName),
                RuntimeTypeInfo.SanitizeFullName(GetFullName(sourceTypeSymbol)),
                StringComparison.Ordinal));
 }
Exemple #2
0
        public void CreateDescriptors_WithPrefixes_ReturnsExpectedAttributeDescriptors(
            Type tagHelperType,
            IEnumerable <TagHelperAttributeDescriptor> expectedAttributeDescriptors,
            string[] expectedErrorMessages)
        {
            // Arrange
            var errorSink = new ErrorSink();

            // Act
            var descriptors = TagHelperDescriptorFactory.CreateDescriptors(
                AssemblyName,
                GetTypeInfo(tagHelperType),
                designTime: false,
                errorSink: errorSink);

            // Assert
            var errors = errorSink.Errors.ToArray();

            Assert.Equal(expectedErrorMessages.Length, errors.Length);

            for (var i = 0; i < errors.Length; i++)
            {
                Assert.Equal(0, errors[i].Length);
                Assert.Equal(SourceLocation.Zero, errors[i].Location);
                Assert.Equal(expectedErrorMessages[i], errors[i].Message, StringComparer.Ordinal);
            }

            var descriptor = Assert.Single(descriptors);

#if DNXCORE50
            // In CoreCLR type forwarding of System.Runtime types causes issues with comparing FullNames for generic types.
            // We'll work around this by sanitizing the type names so that the assembly qualification is removed.
            foreach (var attributeDescriptor in expectedAttributeDescriptors)
            {
                attributeDescriptor.TypeName = RuntimeTypeInfo.SanitizeFullName(attributeDescriptor.TypeName);
            }

            foreach (var attributeDescriptor in descriptor.Attributes)
            {
                attributeDescriptor.TypeName = RuntimeTypeInfo.SanitizeFullName(attributeDescriptor.TypeName);
            }
#endif

            Assert.Equal(
                expectedAttributeDescriptors,
                descriptor.Attributes,
                TagHelperAttributeDescriptorComparer.Default);
        }
Exemple #3
0
        /// <inheritdoc />
        public bool Equals(ITypeInfo other)
        {
            if (other == null)
            {
                return(false);
            }

            var otherSymbolBasedType = other as CodeAnalysisSymbolBasedTypeInfo;

            if (otherSymbolBasedType != null)
            {
                return(otherSymbolBasedType.TypeSymbol == TypeSymbol);
            }

            return(string.Equals(
                       SanitizedFullName,
                       RuntimeTypeInfo.SanitizeFullName(other.FullName),
                       StringComparison.Ordinal));
        }
Exemple #4
0
        private static void AssertEqual(ITypeInfo expected, ITypeInfo actual, bool assertProperties)
        {
            var runtimeType = Assert.IsType <RuntimeTypeInfo>(expected);

            var actualFullName = actual.FullName.Replace(
                CompilationUtility.GeneratedAssemblyName,
                runtimeType.TypeInfo.Assembly.GetName().Name);

            Assert.Equal(expected.Name, actual.Name);
#if DNXCORE50
            Assert.Equal(
                RuntimeTypeInfo.SanitizeFullName(expected.FullName),
                RuntimeTypeInfo.SanitizeFullName(actualFullName));
#endif
            Assert.Equal(expected.IsPublic, actual.IsPublic);
            Assert.Equal(expected.IsAbstract, actual.IsAbstract);
            Assert.Equal(expected.IsGenericType, actual.IsGenericType);
            Assert.Equal(
                expected.ImplementsInterface(TagHelperTypeInfo),
                actual.ImplementsInterface(TagHelperTypeInfo));
            Assert.Equal(
                expected.GetGenericDictionaryParameters(),
                actual.GetGenericDictionaryParameters(),
                new DelegateAssertion <ITypeInfo>((x, y) => AssertEqual(x, y, assertProperties: false)));

            if (assertProperties)
            {
                Assert.Equal(
                    expected.Properties.OrderBy(p => p.Name),
                    actual.Properties.OrderBy(p => p.Name),
                    new DelegateAssertion <IPropertyInfo>((x, y) => AssertEqual(x, y)));
            }

            Assert.True(actual.Equals(expected));
            Assert.True(expected.Equals(actual));
            Assert.Equal(expected.GetHashCode(), actual.GetHashCode());
        }