private IEnumerable <NameMetaData> GetNamedMetaData(Type type, string prefix) { var query = new QueryFluentMetadata(); foreach (PropertyInfo propertyInfo in type.GetProperties()) { if (IsSimpleType(propertyInfo.PropertyType)) { Metadata metadata = query.FindMetadataFor(type, propertyInfo.Name); if (metadata != null) { yield return(new NameMetaData(prefix + propertyInfo.Name, metadata)); } } else { currentLevel++; if (currentLevel <= MaxLevel) { foreach ( NameMetaData named in GetNamedMetaData(propertyInfo.PropertyType, prefix + propertyInfo.Name)) { yield return(named); } } currentLevel--; } } }
internal void MapProperties <T>(StructuralTypeConfiguration <T> configuration) where T : class { var metaDatas = QueryFluentMetadata.GetMetadataFor(typeof(T)).Properties; foreach (var data in metaDatas) { if (data.ModelName == null) { continue; } if (!data.GetMaximumLength().HasValue&& !data.Required.HasValue) { continue; } var methodInfo = PropertyMethodMapping.GetPropertyMappingMethod( configuration.GetType(), typeof(T), data.ModelType); if (methodInfo == null) { continue; } var lambda = ExpressionGenerator.CreateExpressionForProperty(typeof(T), data.ModelName); if (lambda != null) { var propertyConfiguration = (PrimitivePropertyConfiguration)methodInfo.Invoke(configuration, new[] { lambda }); factory.Create(propertyConfiguration).Convert(data, propertyConfiguration); } } }
public PropertyMedata_with_Person() { var query = new QueryFluentMetadata(); firstName = query.GetMetadataFor(typeof(Person), "FirstName"); lastName = query.GetMetadataFor(typeof(Person), "LastName"); }
private IEnumerable <NameMetaData> GetNamedMetaData(Type type, string prefix) { foreach (var propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { var metadata = QueryFluentMetadata.FindMetadataFor(type, propertyInfo.Name); if (metadata != null) { yield return(new NameMetaData(prefix + propertyInfo.Name, metadata)); } if (!IsSimpleType(propertyInfo.PropertyType)) { currentLevel++; if (currentLevel <= MaxLevel) { foreach (var named in GetNamedMetaData(propertyInfo.PropertyType, prefix + propertyInfo.Name)) { yield return(named); } } currentLevel--; } } }
private IEnumerable<NameMetaData> GetNamedMetaData(Type type, string prefix) { var query = new QueryFluentMetadata(); foreach (PropertyInfo propertyInfo in type.GetProperties()) { if (IsSimpleType(propertyInfo.PropertyType)) { Metadata metadata = query.FindMetadataFor(type, propertyInfo.Name); if (metadata != null) yield return new NameMetaData(prefix+propertyInfo.Name, metadata); } else { currentLevel++; if (currentLevel <= MaxLevel) { foreach ( NameMetaData named in GetNamedMetaData(propertyInfo.PropertyType, prefix + propertyInfo.Name)) { yield return named; } } currentLevel--; } } }
public DerivedDerivedClass_Tests() { var query = new QueryFluentMetadata(); id = query.GetMetadataFor(typeof(DerivedDerivedClass), "Id"); title = query.GetMetadataFor(typeof(DerivedDerivedClass), "Title"); }
public PropertyMedata_with_WebUser() { var query = new QueryFluentMetadata(); username = query.GetMetadataFor(typeof(WebUser), "Username"); id = query.GetMetadataFor(typeof(WebUser), "Id"); }
public PropertyMedata_with_WebUserIndexModel() { var query = new QueryFluentMetadata(); username = query.GetMetadataFor(typeof(WebUserIndexModel), "Username"); id = query.GetMetadataFor(typeof(WebUserIndexModel), "Id"); autorName = query.GetMetadataFor(typeof(WebUserIndexModel), "AutorName"); }
public PropertyMedata_with_WebUser() { username = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "Username"); id = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "Id"); lastLogin = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "LastLogin"); passWordHash = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "PasswordHash"); role = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "Role"); bounceCount = QueryFluentMetadata.GetMetadataFor(typeof(WebUser), "BounceCount"); }
public void Apply(IManyToOneInstance instance) { var meta = QueryFluentMetadata.FindMetadataFor(instance.EntityType, instance.Property.Name); if (meta != null && meta.Required.HasValue && meta.Required.Value) { instance.Not.Nullable(); } }
public PropertyMedata_with_WebUserIndexGetModel() { username = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "Username"); id = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "Id"); email = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "EMail"); autorName = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "AutorName"); role = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "Role"); secondaryRoles = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "SecondaryRoles"); passwordHash = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexGetModel), "PasswordHash"); }
public When_FluentMetadataBuilder_builds_metadata_copying_from_other_metadata_that_does_not_apply() { FluentMetadataBuilder.Reset(); try { FluentMetadataBuilder.BuildMetadataDefinitions(GetUnbuildableMetadataDefinitions()); someViewModelRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel)).Rules; someViewModelMyPropertyRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel), "MyProperty").Rules; } catch (Exception ex) { exception = ex; } }
/// <summary> /// Gets a <see cref="T:System.Web.Mvc.ModelMetadata"/> object for each property of a model. /// </summary> /// <param name="container">The container.</param> /// <param name="containerType">The type of the container.</param> /// <returns> /// A <see cref="T:System.Web.Mvc.ModelMetadata"/> object for each property of a model. /// </returns> public override IEnumerable <ModelMetadata> GetMetadataForProperties(object container, Type containerType) { var publicProps = containerType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var propertyMetadata in QueryFluentMetadata.GetMetadataFor(containerType).Properties) { var props = publicProps.Where(p => p.Name == propertyMetadata.ModelName).ToArray(); var prop = props.Length > 1 ? props.GetHiding() : props.SingleOrDefault(); if (prop != null) { yield return(new FluentModelMetadata(propertyMetadata, this, () => prop.GetValue(container, null))); } } }
public When_copying_metadata_from_an_AutoMapped_Type() { FluentMetadataBuilder.Reset(); Mapper.Reset(); Mapper.Initialize(cfg => { cfg.ShouldMapProperty = pi => true; //in order to test NonPublic member mapping as well cfg.CreateMap <Source, Destination>() .ForMember(d => d.Renamed, o => o.MapFrom(s => s.Named)) .ForMember(d => d.IntProperty, o => o.ResolveUsing <FakeResolver, string>(s => s.StringField)); }); Mapper.AssertConfigurationIsValid(); FluentMetadataBuilder.ForAssemblyOfType <Source>(); destinationMetadata = QueryFluentMetadata.GetMetadataFor(typeof(Destination)); }
public void Apply(IPropertyInstance instance) { var meta = QueryFluentMetadata.FindMetadataFor(instance.EntityType, instance.Property.Name); if (meta != null) { if (meta.Required.HasValue && meta.Required.Value) { instance.Not.Nullable(); } var maxLength = meta.GetMaximumLength(); if (maxLength.HasValue && maxLength.Value > 0) { instance.Length(maxLength.Value); } } }
public When_FluentMetadataBuilder_builds_metadata_copying_from_other_metadata() { FluentMetadataBuilder.Reset(); var typesToBuildInLaterBatch = new[] { typeof(SomeTypeInAnotherAssemblyMetadata) }; try { FluentMetadataBuilder.BuildMetadataDefinitions( GetUnbuildableMetadataDefinitions() .Except(typesToBuildInLaterBatch)); FluentMetadataBuilder.BuildMetadataDefinitions(typesToBuildInLaterBatch); someViewModelRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel)).Rules; someViewModelMyPropertyRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel), "MyProperty").Rules; someViewModelMyStringPropertyRules = QueryFluentMetadata.GetMetadataFor(typeof(SomeViewModel), "MyStringProperty").Rules; } catch (Exception ex) { exception = ex; } }
public ClassMetadata_with_Person() { classMetadata = QueryFluentMetadata.GetMetadataFor(typeof(Person)); }
public Content_Metadata_Tests() { query = new QueryFluentMetadata(); }
/// <summary> /// Gets metadata for the specified property. /// </summary> /// <param name="modelAccessor">The model accessor.</param> /// <param name="containerType">The type of the container.</param> /// <param name="propertyName">The property to get the metadata model for.</param> /// <returns> /// A <see cref="T:System.Web.Mvc.ModelMetadata"/> object for the property. /// </returns> public override ModelMetadata GetMetadataForProperty(Func <object> modelAccessor, Type containerType, string propertyName) => new FluentModelMetadata(QueryFluentMetadata.GetMetadataFor(containerType, propertyName), this, modelAccessor);
public BaseClass_Tests() { var query = new QueryFluentMetadata(); id = query.GetMetadataFor(typeof(BaseClass), "Id"); }
public PropertyMedata_with_Person() { var query = new QueryFluentMetadata(); firstName = query.GetMetadataFor(typeof (Person), "FirstName"); lastName = query.GetMetadataFor(typeof (Person), "LastName"); }
public void Content_Title_Is_Required() { var metaData = QueryFluentMetadata.GetMetadataFor(typeof(Content), "Title"); Assert.True(metaData.Required.Value); }
public ClassMetadata_with_WebUser() { classMetadata = QueryFluentMetadata.GetMetadataFor(typeof(WebUser)); }
public ClassMetadata_with_WebUserIndexModel() { classMetadata = QueryFluentMetadata.GetMetadataFor(typeof(WebUserIndexModel)); }
public ClassMetadata_with_Person() { var query = new QueryFluentMetadata(); classMetadata = query.GetMetadataFor(typeof (Person)); }
public ClassMetadata_with_Person() { var query = new QueryFluentMetadata(); classMetadata = query.GetMetadataFor(typeof(Person)); }
public DerivedDerivedClass_Tests() { id = QueryFluentMetadata.GetMetadataFor(typeof(DerivedDerivedClass), "Id"); title = QueryFluentMetadata.GetMetadataFor(typeof(DerivedDerivedClass), "Title"); }
public BaseClass_Tests() { id = QueryFluentMetadata.GetMetadataFor(typeof(BaseClass), "Id"); }
public PropertyMedata_with_Person() { firstName = QueryFluentMetadata.GetMetadataFor(typeof(Person), "FirstName"); lastName = QueryFluentMetadata.GetMetadataFor(typeof(Person), "LastName"); }
public ClassMetadata_with_WebUser() { var query = new QueryFluentMetadata(); classMetadata = query.GetMetadataFor(typeof(WebUser)); }
/// <summary> /// Gets metadata for the specified model accessor and model type. /// </summary> /// <param name="modelAccessor">The model accessor.</param> /// <param name="modelType">The type of the model.</param> /// <returns> /// A <see cref="T:System.Web.Mvc.ModelMetadata"/> object for the specified model accessor and model type. /// </returns> public override ModelMetadata GetMetadataForType(Func <object> modelAccessor, Type modelType) => new FluentModelMetadata(QueryFluentMetadata.GetMetadataFor(modelType), this, modelAccessor);
public ClassMetadata_with_WebUserIndexModel() { var query = new QueryFluentMetadata(); classMetadata = query.GetMetadataFor(typeof(WebUserIndexModel)); }