Пример #1
0
        public void ConvertToRuntimeType_WithTypeAdapter_ReturnsRuntimeType()
        {
            var expectedType = typeof(TheType);
            ITypeInformation typeInformation = TypeAdapter.Create(expectedType);

            Assert.That(typeInformation.ConvertToRuntimeType(), Is.SameAs(expectedType));
        }
        private IPropertyInformation GetNormalizedProperty(IPropertyInformation propertyInformation, ITypeInformation instanceTypeInformation)
        {
            var originalDeclaringType = propertyInformation.GetOriginalDeclaringType();

            // Support for properties declared on instance type and base types
            if (originalDeclaringType.IsAssignableFrom(instanceTypeInformation))
            {
                return(propertyInformation);
            }

            // Support for properties declared on derived types
            if (instanceTypeInformation.IsAssignableFrom(originalDeclaringType))
            {
                return(propertyInformation);
            }

            // Support for properties declared on mixin
            if (Mixins.Utilities.ReflectionUtility.IsMixinType(originalDeclaringType.ConvertToRuntimeType()))
            {
                var instanceRuntimeType          = instanceTypeInformation.ConvertToRuntimeType();
                var interfacePropertyInformation = propertyInformation.FindInterfaceDeclarations()
                                                   .Where(p => MixinTypeUtility.IsAssignableFrom(p.GetOriginalDeclaringType().ConvertToRuntimeType(), instanceRuntimeType))
                                                   .First(
                    () =>
                    new NotSupportedException(
                        string.Format(
                            "The member '{0}.{1}' is not part of any interface introduced onto the target class '{2}'. "
                            + "Only mixed properties that are part of an introduced interface can be used within the sort-expression of a collection property.",
                            propertyInformation.DeclaringType.FullName,
                            propertyInformation.Name,
                            instanceTypeInformation.FullName
                            )));

                return(interfacePropertyInformation);
            }

            // Unreachable due to mapping validation
            throw new NotSupportedException(
                      string.Format(
                          "The member '{0}.{1}' is not part of inheritance hierarchy of class '{2}'. "
                          + "Only properties that are part of the inheritance hierarhcy can be used within the sort-expression of a collection property.",
                          propertyInformation.DeclaringType.FullName,
                          propertyInformation.Name,
                          instanceTypeInformation.FullName
                          ));
        }