public CollectionConfiguration ToConfiguration(PropertyInfo property) { if (!property.PropertyType.IsGenericEnumerable()) { throw new InvalidOperationException("BlockSettingsAttribute is only valid for generic collections"); } var configuration = new CollectionConfiguration(new SingleProperty(property)) { Name = ExpressAs }; if (ImplicitProperty.IsNotEmpty()) { var targetType = property.PropertyType.FindInterfaceThatCloses(typeof(IEnumerable <>)).GetGenericArguments()[0]; var target = Cache.GetPropertiesFor(targetType).SingleOrDefault(x => x.Key.EqualsIgnoreCase(ImplicitProperty)).Value; if (target == null) { throw new InvalidOperationException("Could not find property: " + ImplicitProperty); } configuration.Implicit = new SingleProperty(target); } return(configuration); }
public void get_properties_for_returns_type_properties() { var props = new List <string>(); _cache.ForEachProperty(typeof(Item), p => props.Add(p.Name)); var itemProperties = _cache.GetPropertiesFor <Item>(); itemProperties.Keys.ToList().ShouldHaveTheSameElementsAs(props as IEnumerable <string>); }
public ObjectBlockSettings() { _cache = new TypeDescriptorCache(); _ignored = new List <IIgnoreAccessorPolicy>(); _byAccessor = new Cache <Accessor, CollectionConfiguration>( x => x.InnerProperty.HasAttribute <BlockSettingsAttribute>() ? x.ToCollectionConfiguration() : new CollectionConfiguration(x)); _collectionsFor = new Cache <Type, IList <CollectionConfiguration> >( type => _cache.GetPropertiesFor(type) .Values .Where(x => x.PropertyType.IsGenericEnumerable()) .Select(x => _byAccessor[new SingleProperty(x)]) .ToList()); }