Exemplo n.º 1
0
        public void CanCacheClrBoundTypeMembers()
        {
            //-- arrange

            TypeMember typeInt1          = typeof(int);
            TypeMember typeString1       = typeof(string);
            TypeMember typeArrayOfInt1   = typeof(int[]);
            TypeMember typeListOfString1 = typeof(List <string>);

            //-- act

            TypeMember typeInt2          = typeof(int);
            TypeMember typeString2       = typeof(string);
            TypeMember typeArrayOfInt2   = typeof(int[]);
            TypeMember typeListOfString2 = typeof(List <string>);

            //-- assert

            typeInt2.Should().NotBeNull();
            typeString2.Should().NotBeNull();
            typeArrayOfInt2.Should().NotBeNull();
            typeListOfString2.Should().NotBeNull();

            typeInt2.Should().BeSameAs(typeInt1);
            typeString2.Should().BeSameAs(typeString1);
            typeArrayOfInt2.Should().BeSameAs(typeArrayOfInt1);
            typeListOfString2.Should().BeSameAs(typeListOfString1);

            typeArrayOfInt1.UnderlyingType.Should().BeSameAs(typeInt1);
            typeListOfString1.UnderlyingType.Should().BeSameAs(typeString1);
            typeArrayOfInt2.UnderlyingType.Should().BeSameAs(typeInt1);
            typeListOfString2.UnderlyingType.Should().BeSameAs(typeString1);
        }
Exemplo n.º 2
0
        public void MakeGenericTypeOfBoundTypesResultsInBoundType()
        {
            //-- arrange

            TypeMember typeInt             = typeof(int);
            TypeMember typeString          = typeof(string);
            TypeMember typeIDictionaryOpen = typeof(IDictionary <,>);

            //-- act

            TypeMember constructedType = typeIDictionaryOpen.MakeGenericType(typeInt, typeString);

            //-- assert

            constructedType.ClrBinding.Should().NotBeNull();
            constructedType.ClrBinding.Should().BeSameAs(typeof(IDictionary <int, string>));

            constructedType.Should().NotBeNull();
            constructedType.IsGenericType.Should().BeTrue();
            constructedType.IsGenericTypeDefinition.Should().BeFalse();
            constructedType.GenericTypeDefinition.Should().BeSameAs(typeIDictionaryOpen);
            constructedType.GenericTypeArguments.Count.Should().Be(2);
            constructedType.GenericTypeArguments[0].Should().BeSameAs(typeInt);
            constructedType.GenericTypeArguments[1].Should().BeSameAs(typeString);
        }
Exemplo n.º 3
0
        public void MakeGenericTypeOfMixedBoundAndGeneratedTypesResultsInGeneratedType()
        {
            //-- arrange

            TypeMember typeKey             = typeof(int);
            TypeMember typeValue           = new TypeMember(MemberVisibility.Public, TypeMemberKind.Class, "ClassValue");
            TypeMember typeIDictionaryOpen = typeof(IDictionary <,>);

            //-- act

            TypeMember constructedType = typeIDictionaryOpen.MakeGenericType(typeKey, typeValue);

            //-- assert

            constructedType.ClrBinding.Should().BeNull();

            constructedType.Should().NotBeNull();
            constructedType.IsGenericType.Should().BeTrue();
            constructedType.IsGenericTypeDefinition.Should().BeFalse();
            constructedType.GenericTypeDefinition.Should().BeSameAs(typeIDictionaryOpen);
            constructedType.GenericTypeArguments.Count.Should().Be(2);
            constructedType.GenericTypeArguments[0].Should().BeSameAs(typeKey);
            constructedType.GenericTypeArguments[1].Should().BeSameAs(typeValue);
        }