Пример #1
0
        public void GenericTypeParameterDataContraintsTest()
        {
            var t        = typeof(TestClassDefinition <, , , ,>);
            var assembly = AssemblyData.FromAssembly(t.Assembly);
            var testClassDefinitionData     = TypeDefinitionData.FromType(t);
            var equatableInterfaceData      = ConstructedGenericTypeData.FromType <IEquatable <TestClassDefinition> >();
            var testInterfaceDefinitionData = TypeDefinitionData.FromType <TestInterfaceDefinition>();
            var valueTypeData = TypeDefinitionData.FromType <ValueType>();

            var p1 = testClassDefinitionData.GenericParameters[0];

            Assert.AreEqual(0, p1.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");

            var p2 = testClassDefinitionData.GenericParameters[1];

            Assert.AreEqual(2, p2.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");
            // Note: these may need to be reversed
            Assert.AreEqual(equatableInterfaceData, p2.Constraints[0], "The reported type is not correct.");
            Assert.AreEqual(testInterfaceDefinitionData, p2.Constraints[1], "The reported type is not correct.");

            var p3 = testClassDefinitionData.GenericParameters[2];

            Assert.AreEqual(0, p3.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");

            var p4 = testClassDefinitionData.GenericParameters[3];

            Assert.AreEqual(1, p4.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");
            Assert.AreEqual(valueTypeData, p4.Constraints[0], "The reported type is not correct.");

            var p5 = testClassDefinitionData.GenericParameters[4];

            Assert.AreEqual(0, p5.Constraints.Count, "The number of Constraints on the genertic type parameter is incorrect.");
        }
Пример #2
0
        public void TypeDefinitionDataImplementedInterfacesTest()
        {
            var t        = typeof(TestClassDefinition);
            var assembly = AssemblyData.FromAssembly(t.Assembly);
            var testClassDefinitionData     = TypeDefinitionData.FromType(t);
            var equatableInterfaceData      = ConstructedGenericTypeData.FromType <IEquatable <TestClassDefinition> >();
            var testInterfaceDefinitionData = TypeDefinitionData.FromType <TestInterfaceDefinition>();

            Assert.AreEqual(2, testClassDefinitionData.ImplementedInterfaces.Count, "The TestClassDefinition should only have one externally visiiblt interface.");
            // Note: these may need to be reversed
            Assert.AreEqual(testInterfaceDefinitionData, testClassDefinitionData.ImplementedInterfaces[0], "The reported interface is not correct.");
            Assert.AreEqual(equatableInterfaceData, testClassDefinitionData.ImplementedInterfaces[1], "The reported interface is not correct.");

            Assert.AreEqual(1, testInterfaceDefinitionData.ImplementedInterfaces.Count, "The TestClassDefinition should only have one externally visiiblt interface.");
            Assert.AreEqual(equatableInterfaceData, testInterfaceDefinitionData.ImplementedInterfaces[0], "The reported interface is not correct.");
        }
Пример #3
0
 /// <summary>
 /// The visit implementation for <see cref="ConstructedGenericTypeData"/> instances.
 /// </summary>
 public virtual void VisitConstructedGenericTypeData(ConstructedGenericTypeData item) => DefaultVisit(item);
 public void OnlyReferenceAndIdentityConversionsInVariancesTest()
 {
     Assert.IsFalse(ConstructedGenericTypeData.FromType <IEnumerable <object> >().IsAssignableFromNew(ConstructedGenericTypeData.FromType <IEnumerable <int> >()));
     Assert.IsFalse(ConstructedGenericTypeData.FromType <IEnumerable <int> >().IsAssignableFromNew(ConstructedGenericTypeData.FromType <IEnumerable <byte> >()));
     Assert.IsFalse(ConstructedGenericTypeData.FromType <IEnumerable <int?> >().IsAssignableFromNew(ConstructedGenericTypeData.FromType <IEnumerable <int> >()));
 }