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)); }
private void PropertyFilter_validates_enum_types(PropertyFilter filter) { var properties = new List <PropertyInfo> { new MockPropertyInfo(typeof(AnEnum1), "EnumProp") }; filter.ValidatePropertiesForModelVersion(typeof(AType1), properties); }
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); }
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); }
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))); }
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))); }
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))); }
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))); }
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)); }
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()); }
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); } } }
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); } }
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)); } } } }
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); } } }
private void PropertyFilter_validates_enum_types(PropertyFilter filter) { var properties = new List<PropertyInfo> { new MockPropertyInfo(typeof(AnEnum1), "EnumProp") }; filter.ValidatePropertiesForModelVersion(typeof(AType1), properties); }
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()); }
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)); }
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); }
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); }
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)); }