public void Bind(BindableConfiguration bindableConfiguration, params ICreateExecutableMapping[] configurations) { var candidates = GetCandidateDestinationProperties(bindableConfiguration); var candidateElements = candidates.Select(its => its.PropertyType.ElementType()); var filteredConfigs = configurations.Where(cfg => candidateElements.Contains(cfg.DestinationType)); var candidate2Cfg=new Dictionary<IDescribeMappableProperty, List<ICreateExecutableMapping>>(); foreach (var cand in candidates) { List<ICreateExecutableMapping> cfgs; if(candidate2Cfg.TryGetValue(cand,out cfgs)==false) { candidate2Cfg.Add(cand,cfgs=new List<ICreateExecutableMapping>()); } cfgs.AddRange(filteredConfigs); } foreach (var candidate in candidate2Cfg) { var copy = candidate; foreach (var sourceContext in bindableConfiguration.SourceContexts.Where(it => it.RequiresCollectionConfigurationFor(copy.Key))) { /*be sure we set resolver for each property that has a list element matching*/ foreach (var createExecutableMapping in candidate.Value) { var resolverContext = new ResolverContext(sourceContext.CreateProperty(copy.Key), copy.Key, createExecutableMapping); var resolver = resolvers.CreateListResolver(resolverContext); if(sourceContext.TrySetResolver(candidate.Key, resolver)==false) { Logger.Create(this).Info("{0} will not be overriden on {1} using {2}",candidate.Key,sourceContext,resolver); } } } } }
public void Bind(BindableConfiguration bindableConfiguration, params ICreateExecutableMapping[] configurations) { var candidates = GetCandidateDestinationProperties(bindableConfiguration); var candidateElements = candidates.Select(its => its.PropertyType.ElementType()); var filteredConfigs = configurations.Where(cfg => candidateElements.Contains(cfg.DestinationType)); var candidate2Cfg = new Dictionary <IDescribeMappableProperty, List <ICreateExecutableMapping> >(); foreach (var cand in candidates) { List <ICreateExecutableMapping> cfgs; if (candidate2Cfg.TryGetValue(cand, out cfgs) == false) { candidate2Cfg.Add(cand, cfgs = new List <ICreateExecutableMapping>()); } cfgs.AddRange(filteredConfigs); } foreach (var candidate in candidate2Cfg) { var copy = candidate; foreach (var sourceContext in bindableConfiguration.SourceContexts.Where(it => it.RequiresCollectionConfigurationFor(copy.Key))) { /*be sure we set resolver for each property that has a list element matching*/ foreach (var createExecutableMapping in candidate.Value) { var resolverContext = new ResolverContext(sourceContext.CreateProperty(copy.Key), copy.Key, createExecutableMapping); var resolver = resolvers.CreateListResolver(resolverContext); if (sourceContext.TrySetResolver(candidate.Key, resolver) == false) { Logger.Create(this).Info("{0} will not be overriden on {1} using {2}", candidate.Key, sourceContext, resolver); } } } } }
public void Bind(BindableConfiguration bindableConfiguration, params ICreateExecutableMapping[] configurations) { if (configurations == null || configurations.Length == 0) { return; } var children = configurations.ToDictionary(k => new ConfigurationPropertyCriterion(k), v => v); foreach (var childCfg in children) { KeyValuePair <ConfigurationPropertyCriterion, ICreateExecutableMapping> cfg = childCfg; foreach (var destinationProperty in bindableConfiguration.DestinationProperties.Where(destProp => cfg.Key.IsSatisfiedBy(destProp))) { var copy = destinationProperty; foreach (var sourceContext in bindableConfiguration.SourceContexts.Where(sourceContext => sourceContext.RequiresComponentConfigurationFor(copy))) { Logger.Create(this).Debug("Extending configuration on '{0}' from '{1}' for property '{2}'", bindableConfiguration.DestinationType, childCfg.Value.DestinationType, copy.Name); var resolverContext = new ResolverContext(sourceContext.CreateProperty(destinationProperty), destinationProperty, childCfg.Value); if (sourceContext.TrySetResolver(destinationProperty, resolvers.CreateRedirectingConfigurationResolver(resolverContext)) == false) { Logger.Create(this).Info("{0} will not be overriden on {1} using {2}", destinationProperty, sourceContext, resolverContext); } } } } }
public void Bind(BindableConfiguration bindableConfiguration,params ICreateExecutableMapping[] configurations) { if (configurations == null || configurations.Length == 0) return; var children = configurations.ToDictionary(k => new ConfigurationPropertyCriterion(k), v => v); foreach (var childCfg in children) { KeyValuePair<ConfigurationPropertyCriterion, ICreateExecutableMapping> cfg = childCfg; foreach (var destinationProperty in bindableConfiguration.DestinationProperties.Where(destProp => cfg.Key.IsSatisfiedBy(destProp))) { var copy = destinationProperty; foreach (var sourceContext in bindableConfiguration.SourceContexts.Where(sourceContext => sourceContext.RequiresComponentConfigurationFor(copy))) { Logger.Create(this).Debug("Extending configuration on '{0}' from '{1}' for property '{2}'", bindableConfiguration.DestinationType, childCfg.Value.DestinationType, copy.Name); var resolverContext = new ResolverContext(sourceContext.CreateProperty(destinationProperty), destinationProperty, childCfg.Value); if(sourceContext.TrySetResolver(destinationProperty, resolvers.CreateRedirectingConfigurationResolver(resolverContext))==false) { Logger.Create(this).Info("{0} will not be overriden on {1} using {2}", destinationProperty, sourceContext, resolverContext); } } } } }
public IResolveValue CreateRedirectingConfigurationResolver(ResolverContext resolverContext) { return new RedirectingConfigurationResolver(resolverContext.SourceProperty,resolverContext.Configuration); }
public IResolveValue CreateListResolver(ResolverContext resolverContext) { return new ListResolver(resolverContext.SourceProperty,resolverContext.Configuration,activate); }