// Returns true if the bind should continue, false to skip
        bool ValidateBindTypes(Type concreteType, Type contractType)
        {
            bool isConcreteOpenGenericType = concreteType.IsOpenGenericType();
            bool isContractOpenGenericType = contractType.IsOpenGenericType();

            if (isConcreteOpenGenericType != isContractOpenGenericType)
            {
                return(false);
            }

#if !(UNITY_WSA && ENABLE_DOTNET)
            // TODO: Is it possible to do this on WSA?

            if (isContractOpenGenericType)
            {
                Assert.That(isConcreteOpenGenericType);

                if (TypeExtensions.IsAssignableToGenericType(concreteType, contractType))
                {
                    return(true);
                }
            }
            else if (concreteType.DerivesFromOrEqual(contractType))
            {
                return(true);
            }
#else
            if (concreteType.DerivesFromOrEqual(contractType))
            {
                return(true);
            }
#endif

            if (BindInfo.InvalidBindResponse == InvalidBindResponses.Assert)
            {
                throw Assert.CreateException(
                          "Expected type '{0}' to derive from or be equal to '{1}'", concreteType, contractType);
            }

            Assert.IsEqual(BindInfo.InvalidBindResponse, InvalidBindResponses.Skip);
            return(false);
        }
Example #2
0
        public static void AssertIsDerivedFromType(Type concreteType, Type parentType)
        {
#if !(UNITY_WSA && ENABLE_DOTNET)
            // TODO: Is it possible to do this on WSA?

            Assert.That(parentType.IsOpenGenericType() == concreteType.IsOpenGenericType(),
                        "Invalid type given during bind command.  Expected type '{0}' and type '{1}' to both either be open generic types or not open generic types", parentType, concreteType);

            if (parentType.IsOpenGenericType())
            {
                Assert.That(concreteType.IsOpenGenericType());
                Assert.That(TypeExtensions.IsAssignableToGenericType(concreteType, parentType),
                            "Invalid type given during bind command.  Expected open generic type '{0}' to derive from open generic type '{1}'", concreteType, parentType);
            }
            else
#endif
            {
                Assert.That(concreteType.DerivesFromOrEqual(parentType),
                            "Invalid type given during bind command.  Expected type '{0}' to derive from type '{1}'", concreteType, parentType.Name());
            }
        }