コード例 #1
0
        public void PropertyFilter_includes_enum_and_spatial_properties_if_V3_features_are_supported()
        {
            var filteredProperties = new PropertyFilter().GetProperties(typeof(AType1), declaredOnly: false);

            Assert.Equal(
                new[] { "EnumProp", "Geography", "Geometry" },
                filteredProperties.Select(f => f.Name).OrderBy(n => n));
        }
コード例 #2
0
        private void PropertyFilter_validates_enum_types(PropertyFilter filter)
        {
            var properties = new List <PropertyInfo>
            {
                new MockPropertyInfo(typeof(AnEnum1), "EnumProp")
            };

            filter.ValidatePropertiesForModelVersion(typeof(AType1), properties);
        }
コード例 #3
0
        private void PropertyFilter_validates_spatial_types(PropertyFilter filter)
        {
            var properties = new List <PropertyInfo>
            {
                new MockPropertyInfo(typeof(DbGeography), "Geography"),
                new MockPropertyInfo(typeof(DbGeometry), "Geometry")
            };

            filter.ValidatePropertiesForModelVersion(new MockType(), properties);
        }
コード例 #4
0
        private void PropertyFilter_validates_enum_types(PropertyFilter filter)
        {
            var mockType = new MockType();

            mockType.Setup(m => m.IsEnum).Returns(true);

            var properties = new List <PropertyInfo>
            {
                new MockPropertyInfo(mockType, "EnumProp")
            };

            filter.ValidatePropertiesForModelVersion(mockType, properties);
        }
コード例 #5
0
        public void PropertyFilter_finds_declared_properties_on_derived_type()
        {
            var propertyNames = new[]
                                    {
                                        "PublicDerived"
                                    };

            var properties = new PropertyFilter().GetProperties(
                typeof(PropertyFilterTests_Derived), true, Enumerable.Empty<PropertyInfo>());

            Assert.Equal(propertyNames.Length, properties.Count());
            Assert.True(properties.All(x => propertyNames.Contains(x.Name)));
        }
コード例 #6
0
        public void PropertyFilter_finds_declared_properties_on_derived_type()
        {
            var propertyNames = new[]
            {
                "PublicDerived"
            };

            var properties = new PropertyFilter().GetProperties(
                typeof(PropertyFilterTests_Derived), true, Enumerable.Empty <PropertyInfo>());

            Assert.Equal(propertyNames.Length, properties.Count());
            Assert.True(properties.All(x => propertyNames.Contains(x.Name)));
        }
コード例 #7
0
        public void PropertyFilter_finds_all_properties_on_derived_type()
        {
            var propertyNames = new[]
                                    {
                                        "PublicBase",
                                        "PublicBaseForNew",
                                        "PublicVirtualBase",
                                        "PublicVirtualBase2",
                                        "InterfaceImplicit",
                                        "PublicDerived"
                                    };

            var properties = new PropertyFilter().GetProperties(
                typeof(PropertyFilterTests_Derived), false, Enumerable.Empty<PropertyInfo>());

            Assert.Equal(propertyNames.Length, properties.Count());
            Assert.True(properties.All(x => propertyNames.Contains(x.Name)));
        }
コード例 #8
0
        public void PropertyFilter_finds_all_properties_on_derived_type()
        {
            var propertyNames = new[]
            {
                "PublicBase",
                "PublicBaseForNew",
                "PublicVirtualBase",
                "PublicVirtualBase2",
                "InterfaceImplicit",
                "PublicDerived"
            };

            var properties = new PropertyFilter().GetProperties(
                typeof(PropertyFilterTests_Derived), false, Enumerable.Empty <PropertyInfo>());

            Assert.Equal(propertyNames.Length, properties.Count());
            Assert.True(properties.All(x => propertyNames.Contains(x.Name)));
        }
コード例 #9
0
        public void PropertyFilter_includes_enum_and_spatial_properties_if_V3_features_are_supported()
        {
            var mockType = new MockType();

            mockType.Setup(m => m.IsEnum).Returns(true);

            var properties = new PropertyInfo[]
            {
                new MockPropertyInfo(typeof(DbGeography), "Geography"),
                new MockPropertyInfo(typeof(DbGeometry), "Geometry"),
                new MockPropertyInfo(mockType, "EnumProp")
            };

            mockType.Setup(m => m.GetProperties(It.IsAny <BindingFlags>())).Returns(properties);

            var filteredProperties = new PropertyFilter().GetProperties(mockType, declaredOnly: false);

            properties.All(p => filteredProperties.Select(f => f.Name).Contains(p.Name));
        }
コード例 #10
0
        public void PropertyFilter_excludes_enum_and_spatial_properties_if_V3_features_are_not_supported()
        {
            var mockType = new MockType();

            mockType.Setup(m => m.IsEnum).Returns(true);

            var properties = new PropertyInfo[]
            {
                new MockPropertyInfo(typeof(DbGeography), "Geography"),
                new MockPropertyInfo(typeof(DbGeometry), "Geometry"),
                new MockPropertyInfo(mockType, "EnumProp")
            };

            mockType.Setup(m => m.GetProperties(It.IsAny <BindingFlags>())).Returns(properties);

            var filteredProperties = new PropertyFilter(DbModelBuilderVersion.V4_1).GetProperties(mockType, declaredOnly: false);

            Assert.Equal(0, filteredProperties.Count());
        }
コード例 #11
0
ファイル: TypeMapper.cs プロジェクト: dotnet/ef6tools
        private void MapStructuralElements <TStructuralTypeConfiguration>(
            Type type,
            ICollection <MetadataProperty> annotations,
            Action <PropertyMapper, PropertyInfo> propertyMappingAction,
            Func <TStructuralTypeConfiguration> structuralTypeConfiguration)
            where TStructuralTypeConfiguration : StructuralTypeConfiguration
        {
            // PERF: this code is part of a critical section, consider its performance when refactoring
            DebugCheck.NotNull(type);
            DebugCheck.NotNull(annotations);
            DebugCheck.NotNull(propertyMappingAction);
            DebugCheck.NotNull(structuralTypeConfiguration);

            annotations.SetClrType(type);

            new AttributeMapper(_mappingContext.AttributeProvider).Map(type, annotations);

            var propertyMapper = new PropertyMapper(this);

            var properties = new PropertyFilter(_mappingContext.ModelBuilderVersion)
                             .GetProperties(
                type,
                /*declaredOnly:*/ false,
                _mappingContext.ModelConfiguration.GetConfiguredProperties(type),
                _mappingContext.ModelConfiguration.StructuralTypes).ToList();

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var i = 0; i < properties.Count; ++i)
            {
                var propertyInfo = properties[i];
                _mappingContext.ConventionsConfiguration.ApplyPropertyConfiguration(
                    propertyInfo, _mappingContext.ModelConfiguration);
                _mappingContext.ConventionsConfiguration.ApplyPropertyTypeConfiguration(
                    propertyInfo, structuralTypeConfiguration, _mappingContext.ModelConfiguration);

                if (!_mappingContext.ModelConfiguration.IsIgnoredProperty(type, propertyInfo))
                {
                    propertyMappingAction(propertyMapper, propertyInfo);
                }
            }
        }
コード例 #12
0
        public void ValidatePropertiesForModelVersion(
            Type type,
            IEnumerable <PropertyInfo> explicitlyMappedProperties)
        {
            if (this._modelBuilderVersion == DbModelBuilderVersion.Latest || this.EdmV3FeaturesSupported)
            {
                return;
            }
            PropertyInfo propertyInfo = explicitlyMappedProperties.FirstOrDefault <PropertyInfo>((Func <PropertyInfo, bool>)(p =>
            {
                if (!PropertyFilter.IsEnumType(p.PropertyType))
                {
                    return(PropertyFilter.IsSpatialType(p.PropertyType));
                }
                return(true);
            }));

            if (propertyInfo != (PropertyInfo)null)
            {
                throw Error.UnsupportedUseOfV3Type((object)type.Name, (object)propertyInfo.Name);
            }
        }
コード例 #13
0
        private void LiftInheritedProperties(
            Type type, EntityType entityType, EntityTypeConfiguration entityTypeConfiguration)
        {
            DebugCheck.NotNull(type);
            DebugCheck.NotNull(entityType);

            var members = entityType.DeclaredMembers.ToList();

            var declaredProperties
                = new PropertyFilter(_mappingContext.ModelBuilderVersion)
                  .GetProperties(
                      type,
                      /*declaredOnly:*/ true,
                      _mappingContext.ModelConfiguration.GetConfiguredProperties(type),
                      _mappingContext.ModelConfiguration.StructuralTypes);

            foreach (var member in members)
            {
                var propertyInfo = member.GetClrPropertyInfo();

                if (!declaredProperties.Contains(propertyInfo))
                {
                    var navigationProperty = member as NavigationProperty;

                    if (navigationProperty != null)
                    {
                        _mappingContext.Model.RemoveAssociationType(navigationProperty.Association);
                    }

                    entityType.RemoveMember(member);

                    if (entityTypeConfiguration != null)
                    {
                        entityTypeConfiguration.RemoveProperty(new PropertyPath(propertyInfo));
                    }
                }
            }
        }
コード例 #14
0
        private void MapStructuralElements <TStructuralTypeConfiguration>(
            Type type,
            ICollection <MetadataProperty> annotations,
            Action <PropertyMapper, PropertyInfo> propertyMappingAction,
            Func <TStructuralTypeConfiguration> structuralTypeConfiguration)
            where TStructuralTypeConfiguration : StructuralTypeConfiguration
        {
            annotations.SetClrType(type);
            new AttributeMapper(this._mappingContext.AttributeProvider).Map(type, annotations);
            PropertyMapper      propertyMapper = new PropertyMapper(this);
            List <PropertyInfo> list           = new PropertyFilter(this._mappingContext.ModelBuilderVersion).GetProperties(type, false, this._mappingContext.ModelConfiguration.GetConfiguredProperties(type), this._mappingContext.ModelConfiguration.StructuralTypes, false).ToList <PropertyInfo>();

            for (int index = 0; index < list.Count; ++index)
            {
                PropertyInfo propertyInfo = list[index];
                this._mappingContext.ConventionsConfiguration.ApplyPropertyConfiguration(propertyInfo, this._mappingContext.ModelConfiguration);
                this._mappingContext.ConventionsConfiguration.ApplyPropertyTypeConfiguration <TStructuralTypeConfiguration>(propertyInfo, structuralTypeConfiguration, this._mappingContext.ModelConfiguration);
                if (!this._mappingContext.ModelConfiguration.IsIgnoredProperty(type, propertyInfo))
                {
                    propertyMappingAction(propertyMapper, propertyInfo);
                }
            }
        }
コード例 #15
0
        private void PropertyFilter_validates_enum_types(PropertyFilter filter)
        {
            var properties = new List<PropertyInfo>
                {
                    new MockPropertyInfo(typeof(AnEnum1), "EnumProp")
                };

            filter.ValidatePropertiesForModelVersion(typeof(AType1), properties);
        }
コード例 #16
0
        public void PropertyFilter_excludes_enum_and_spatial_properties_if_V3_features_are_not_supported()
        {
            var mockType = new MockType();
            mockType.Setup(m => m.IsEnum).Returns(true);

            var properties = new PropertyInfo[]
                                 {
                                     new MockPropertyInfo(typeof(DbGeography), "Geography"),
                                     new MockPropertyInfo(typeof(DbGeometry), "Geometry"),
                                     new MockPropertyInfo(mockType, "EnumProp")
                                 };

            mockType.Setup(m => m.GetProperties(It.IsAny<BindingFlags>())).Returns(properties);

            var filteredProperties = new PropertyFilter(DbModelBuilderVersion.V4_1).GetProperties(mockType, declaredOnly: false);

            Assert.Equal(0, filteredProperties.Count());
        }
コード例 #17
0
        public void PropertyFilter_includes_enum_and_spatial_properties_if_V3_features_are_supported()
        {
            var mockType = new MockType();
            mockType.Setup(m => m.IsEnum).Returns(true);

            var properties = new PropertyInfo[]
                                 {
                                     new MockPropertyInfo(typeof(DbGeography), "Geography"),
                                     new MockPropertyInfo(typeof(DbGeometry), "Geometry"),
                                     new MockPropertyInfo(mockType, "EnumProp")
                                 };

            mockType.Setup(m => m.GetProperties(It.IsAny<BindingFlags>())).Returns(properties);

            var filteredProperties = new PropertyFilter().GetProperties(mockType, declaredOnly: false);

            properties.All(p => filteredProperties.Select(f => f.Name).Contains(p.Name));
        }
コード例 #18
0
        private void PropertyFilter_validates_spatial_types(PropertyFilter filter)
        {
            var properties = new List<PropertyInfo>
                                 {
                                     new MockPropertyInfo(typeof(DbGeography), "Geography"),
                                     new MockPropertyInfo(typeof(DbGeometry), "Geometry")
                                 };

            filter.ValidatePropertiesForModelVersion(new MockType(), properties);
        }
コード例 #19
0
        private void PropertyFilter_validates_enum_types(PropertyFilter filter)
        {
            var mockType = new MockType();
            mockType.Setup(m => m.IsEnum).Returns(true);

            var properties = new List<PropertyInfo>
                                 {
                                     new MockPropertyInfo(mockType, "EnumProp")
                                 };

            filter.ValidatePropertiesForModelVersion(mockType, properties);
        }
コード例 #20
0
        public void PropertyFilter_includes_enum_and_spatial_properties_if_V3_features_are_supported()
        {
            var filteredProperties = new PropertyFilter().GetProperties(typeof(AType1), declaredOnly: false);

            Assert.Equal(
                new[] { "EnumProp", "Geography", "Geometry" },
                filteredProperties.Select(f => f.Name).OrderBy(n => n));
        }
コード例 #21
0
 public IEnumerable <PropertyInfo> GetProperties(
     Type type,
     bool declaredOnly,
     IEnumerable <PropertyInfo> explicitlyMappedProperties = null,
     IEnumerable <Type> knownTypes = null,
     bool includePrivate           = false)
 {
     explicitlyMappedProperties = explicitlyMappedProperties ?? Enumerable.Empty <PropertyInfo>();
     knownTypes = knownTypes ?? Enumerable.Empty <Type>();
     this.ValidatePropertiesForModelVersion(type, explicitlyMappedProperties);
     return((declaredOnly ? type.GetDeclaredProperties() : type.GetNonHiddenProperties()).Where <PropertyInfo>((Func <PropertyInfo, bool>)(p =>
     {
         if (!p.IsStatic())
         {
             return p.IsValidStructuralProperty();
         }
         return false;
     })).Select(p => new{ p = p, m = p.Getter() }).Where(_param1 =>
     {
         if (!includePrivate && !_param1.m.IsPublic && (!explicitlyMappedProperties.Contains <PropertyInfo>(_param1.p) && !knownTypes.Contains <Type>(_param1.p.PropertyType)) || declaredOnly && !type.BaseType().GetInstanceProperties().All <PropertyInfo>((Func <PropertyInfo, bool>)(bp => bp.Name != _param1.p.Name)) || !this.EdmV3FeaturesSupported && (PropertyFilter.IsEnumType(_param1.p.PropertyType) || PropertyFilter.IsSpatialType(_param1.p.PropertyType)))
         {
             return false;
         }
         if (!this.Ef6FeaturesSupported)
         {
             return !_param1.p.PropertyType.IsNested;
         }
         return true;
     }).Select(_param0 => _param0.p));
 }