public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty) { /*for now, we are just answering this question by the property's name*/ var key = destinationProperty2Resolver.Keys.First(its => string.Equals(its.Name, destinationProperty.Name)); return(destinationProperty2Resolver[key]); }
public DestinationConfigurationMemento(Type destinationType, IDescribeMappableProperty[] destinationProperties, ISourceContext[] sourceContexts, Convention[] conventions) { DestinationType = destinationType; DestinationProperties = destinationProperties; SourceContexts = sourceContexts; Conventions = conventions; }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { var nested = context.Nested(SourceProperty, destinationProperty); var executable = executor.CreateExecutableMapping(nested.SourceType); executable.Execute(nested); return new Result(true, nested.Destination); }
public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty) { var container = inner as IContainResolvers; if (container == null) throw new DittoExecutionException("{0} is not a resolver container",inner); return container.GetResolver(destinationProperty); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { var destValue = context.GetDestinationPropertyValue(destinationProperty.Name); if (destinationProperty.PropertyType.IsDefaultOrEmpty(destValue) == false) return Result.Unresolved; return inner.TryResolve(context, destinationProperty); }
private bool IsCustomTypeAndCustomResolverSet(IDescribeMappableProperty prop) { var resolver = destinationProperty2Resolver[prop]; return(prop.IsCustomType && typeof(RequiresComponentMappingResolver).IsInstanceOfType(resolver) == false && typeof(RequiresCollectionMappingResolver).IsInstanceOfType(resolver) == false); }
public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty) { if (WillResolve(destinationProperty) == false) { throw new InvalidOperationException("Resolver not configured for " + destinationProperty); } return(resolver); }
public IAssignValue BuildValueAssignment(IDescribeMappableProperty destinationProperty) { if (destinationProperty == null) { throw new ArgumentNullException("destinationProperty"); } return(valueAssignments.Create(destination, destinationProperty)); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { if (inner == null) { inner = getResolver(); } return(inner.TryResolve(context, destinationProperty)); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { if(inner==null) { inner = getResolver(); } return inner.TryResolve(context, destinationProperty); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { //we need to keep the SOURCE the same, but change the destination var nested = context.Nested(destinationProperty); var executable = executor.CreateExecutableMapping(nested.SourceType); executable.Execute(nested); return new Result(true, nested.Destination); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { var nested = context.Nested(SourceProperty, destinationProperty); var executable = executor.CreateExecutableMapping(nested.SourceType); executable.Execute(nested); return(new Result(true, nested.Destination)); }
public NullSourceContext(IDescribeMappableProperty sourceProperty, ICreateValueAssignment valueAssignments, IInvoke invoke, IActivate activate) { this.valueAssignments = valueAssignments; this.invoke = invoke; this.activate = activate; SourceType = sourceProperty.PropertyType; Source = null; }
public IResolutionContext CreateNestedParallelContext(IDescribeMappableProperty sourceProperty, IDescribeMappableProperty destinationProperty, IResolutionContext parentContext) { var src = GetSourceValue(parentContext.Source, sourceProperty); var dest = GetDestValue(src,parentContext.Destination, destinationProperty); if (src == null && destinationProperty.IsCustomType) return new NullSourceContext(sourceProperty, valueAssignments, invoke, activate); return CreateContext(src, dest); }
public NullSourceContext(IDescribeMappableProperty sourceProperty, ICreateValueAssignment valueAssignments, IInvoke invoke, IActivate activate) { this.valueAssignments = valueAssignments; this.invoke = invoke; this.activate = activate; SourceType = sourceProperty.PropertyType; Source = null; }
public void Source(IDescribeMappableProperty[] destinationProperties) { var cacheable = destinationProperties.Where(WillResolve).ToArray(); foreach (var property in cacheable) { cachedResolvers[property]=TryGetCandidate(property); } }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { if (sourced != null) { return(sourced.TryResolve(context, destinationProperty)); } return(UsingReflection(context.SourceType, context.Source)); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { if(GetValue==null) throw new InvalidOperationException("GetValue was not assigned to this resolver."); if (context.Source == null) return Result.Unresolved; return new Result(true,GetValue(context.Source)); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { //we need to keep the SOURCE the same, but change the destination var nested = context.Nested(destinationProperty); var executable = executor.CreateExecutableMapping(nested.SourceType); executable.Execute(nested); return(new Result(true, nested.Destination)); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { if (typeof(TSource).IsAssignableFrom(context.SourceType) == false) { return(Result.Unresolved); } return(new Result(true, lambda((TSource)context.Source))); }
public ValueAssignment(object destination, IDescribeMappableProperty destinationProperty,IValueConverterContainer valueConverters, IInvoke invoke) { if (destinationProperty == null) throw new ArgumentNullException("destinationProperty"); this.destination = destination; this.destinationProperty = destinationProperty; this.invoke = invoke; this.valueConverters = valueConverters ?? NullValueConverterContainer.Instance; }
public AssignableValue(object value, IDescribeMappableProperty destinationProperty, IValueConverterContainer valueConverters) { if (destinationProperty == null) throw new ArgumentNullException("destinationProperty"); this.valueConverters = valueConverters ?? NullValueConverterContainer.Instance; this.destinationProperty = destinationProperty; this.originalValue = value; destinationValue = value; TryConvert(); }
private void AssertOverrideable(IDescribeMappableProperty destinationProperty) { IResolveValue resolver; if (destinationProperty2Resolver.TryGetValue(destinationProperty, out resolver) == false || resolver is IOverrideable) { return; } throw new DittoConfigurationException("Destination property '{0}' already has a manually, or conventioned, configured resolver from source type '{1}'", destinationProperty, SourceType); }
public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty) { var container = inner as IContainResolvers; if (container == null) { throw new DittoExecutionException("{0} is not a resolver container", inner); } return(container.GetResolver(destinationProperty)); }
private object GetSourceValue(object src, IDescribeMappableProperty sourceProperty) { var collectionSpec = new SupportedCollectionTypeSpecification(); if (collectionSpec.IsSatisfiedBy(src) == false) { return invoke.GetValue(sourceProperty.Name, src); } return collectionSpec.GetValue(src, sourceProperty as IDescribePropertyElement); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { var destValue = context.GetDestinationPropertyValue(destinationProperty.Name); if (destinationProperty.PropertyType.IsDefaultOrEmpty(destValue) == false) { return(Result.Unresolved); } return(inner.TryResolve(context, destinationProperty)); }
private object GetSourceValue(object src, IDescribeMappableProperty sourceProperty) { var collectionSpec = new SupportedCollectionTypeSpecification(); if (collectionSpec.IsSatisfiedBy(src) == false) { return(invoke.GetValue(sourceProperty.Name, src)); } return(collectionSpec.GetValue(src, sourceProperty as IDescribePropertyElement)); }
public ConfigurationValidator(Type destinationType, IDescribeMappableProperty[] destinationProperties, IContainResolvers[] resolverContainers) { if (destinationProperties.Length == 0) throw new DittoConfigurationException("Destination properties have not been queried for {0}",destinationType); missingProperties = new MissingProperties(); this.destinationType = destinationType; this.destinationProperties = destinationProperties; this.resolverContainers = resolverContainers; }
public bool WillResolve(IDescribeMappableProperty destinationProperty) { var container = inner as IContainResolvers; if (container == null) { return(false); } return(container.WillResolve(destinationProperty)); }
public IDescribeMappableProperty CreateProperty(IDescribeMappableProperty destinationProperty) { var resolver = destinationProperty2Resolver[destinationProperty]; var redirected = resolver as IRedirected; var srcPropName = redirected == null ? destinationProperty.Name : redirected.SourceProperty.Name; var sourceProperty = SourceType.GetProperty(srcPropName); if(sourceProperty==null) throw new DittoConfigurationException("Cannot find property '{0}' for source '{1}'",destinationProperty,SourceType); return new MappableProperty(sourceProperty); }
public IResolutionContext CreateNestedParallelContext(IDescribeMappableProperty sourceProperty, IDescribeMappableProperty destinationProperty, IResolutionContext parentContext) { var src = GetSourceValue(parentContext.Source, sourceProperty); var dest = GetDestValue(src, parentContext.Destination, destinationProperty); if (src == null && destinationProperty.IsCustomType) { return(new NullSourceContext(sourceProperty, valueAssignments, invoke, activate)); } return(CreateContext(src, dest)); }
public bool TrySetResolver(IDescribeMappableProperty destinationProperty, IResolveValue resolver) { IResolveValue current; if (destinationProperty2Resolver.TryGetValue(destinationProperty, out current) == false || current is IOverrideable) { destinationProperty2Resolver[destinationProperty] = resolver; return(true); } return(false); }
public ValueAssignment(object destination, IDescribeMappableProperty destinationProperty, IValueConverterContainer valueConverters, IInvoke invoke) { if (destinationProperty == null) { throw new ArgumentNullException("destinationProperty"); } this.destination = destination; this.destinationProperty = destinationProperty; this.invoke = invoke; this.valueConverters = valueConverters ?? NullValueConverterContainer.Instance; }
public AssignableValue(object value, IDescribeMappableProperty destinationProperty, IValueConverterContainer valueConverters) { if (destinationProperty == null) { throw new ArgumentNullException("destinationProperty"); } this.valueConverters = valueConverters ?? NullValueConverterContainer.Instance; this.destinationProperty = destinationProperty; this.originalValue = value; destinationValue = value; TryConvert(); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { if (GetValue == null) { throw new InvalidOperationException("GetValue was not assigned to this resolver."); } if (context.Source == null) { return(Result.Unresolved); } return(new Result(true, GetValue(context.Source))); }
public bool WillResolve(IDescribeMappableProperty destinationProperty) { var prop = destinationProperty2Resolver.Keys.FirstOrDefault(its => its.Name == destinationProperty.Name); if (prop == null) { return(false); } return(prop.IsCustomType == false || IsCustomTypeAndCustomResolverSet(prop)); }
private IResolveValue CreateDefaultResolver(IDescribeMappableProperty destinationProperty) { if (destinationProperty.IsCollection && destinationProperty.ElementType.IsCustomType) { return(new RequiresCollectionMappingResolver()); } if (destinationProperty.IsCustomType) { return(new RequiresComponentMappingResolver()); } return(new OverrideablePropertyNameResolver(destinationProperty.Name)); }
public IDescribeMappableProperty CreateProperty(IDescribeMappableProperty destinationProperty) { var resolver = destinationProperty2Resolver[destinationProperty]; var redirected = resolver as IRedirected; var srcPropName = redirected == null ? destinationProperty.Name : redirected.SourceProperty.Name; var sourceProperty = SourceType.GetProperty(srcPropName); if (sourceProperty == null) { throw new DittoConfigurationException("Cannot find property '{0}' for source '{1}'", destinationProperty, SourceType); } return(new MappableProperty(sourceProperty)); }
public bool Equals(IDescribeMappableProperty other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.DeclaringType, DeclaringType) && Equals(other.Name, Name) && Equals(other.PropertyType, PropertyType)); }
private object GetDestValue(object src, object dest,IDescribeMappableProperty destinationProperty) { var collectionSpec = new SupportedCollectionTypeSpecification(); if (collectionSpec.IsSatisfiedBy(src) == false) { if (collectionSpec.IsElement(destinationProperty)) { return activate.CreateInstance(destinationProperty.PropertyType); } return invoke.GetValue(destinationProperty.Name, dest) ?? activate.CreateInstance(destinationProperty.PropertyType); } return activate.CreateCollectionInstance(destinationProperty.PropertyType, collectionSpec.GetLength(src)); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { if (executor == null) { throw new DittoConfigurationException("UnflatteningResolver never bound an executable mapping on component type '{0}' for destination '{1}'. " + Environment.NewLine+ "Be sure the type '{0}' is configured as a destination with source '{2}'",destinationType,context.Destination,context.SourceType); } //we need to keep the SOURCE the same, but change the destination var nested = context.Nested(destinationProperty); var executable = executor.CreateExecutableMapping(nested.SourceType); executable.Execute(nested); return new Result(true, nested.Destination); }
private object GetDestValue(object src, object dest, IDescribeMappableProperty destinationProperty) { var collectionSpec = new SupportedCollectionTypeSpecification(); if (collectionSpec.IsSatisfiedBy(src) == false) { if (collectionSpec.IsElement(destinationProperty)) { return(activate.CreateInstance(destinationProperty.PropertyType)); } return(invoke.GetValue(destinationProperty.Name, dest) ?? activate.CreateInstance(destinationProperty.PropertyType)); } return(activate.CreateCollectionInstance(destinationProperty.PropertyType, collectionSpec.GetLength(src))); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { if (executor == null) { throw new DittoConfigurationException("UnflatteningResolver never bound an executable mapping on component type '{0}' for destination '{1}'. " + Environment.NewLine + "Be sure the type '{0}' is configured as a destination with source '{2}'", destinationType, context.Destination, context.SourceType); } //we need to keep the SOURCE the same, but change the destination var nested = context.Nested(destinationProperty); var executable = executor.CreateExecutableMapping(nested.SourceType); executable.Execute(nested); return(new Result(true, nested.Destination)); }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { var collectionContext = context.Nested(sourceProperty, destinationProperty); var src = (IList) context.GetSourcePropertyValue(sourceProperty.Name); var dest = (IList)activate.CreateCollectionInstance(destinationProperty.PropertyType, src.Count); for (int i = 0; i < src.Count; i++) { var sourceElement = sourceProperty.ElementAt(i); var elementContext = collectionContext.Nested(sourceElement, destinationProperty.ElementAt(i)); var nestedExecutor = this.executor.CreateExecutableMapping(sourceElement.PropertyType); nestedExecutor.Execute(elementContext); dest.AddElement(elementContext.Destination,i); } return new Result(true, dest); }
private IResolveValue TryGetCandidate(IDescribeMappableProperty mappableProperty) { IResolveValue candidate=null; foreach (var container in containers) { if (container.WillResolve(mappableProperty) == false) continue; IContainResolvers copy = container; candidate = copy.GetResolver(mappableProperty); if (typeof(IOverrideable).IsInstanceOfType(candidate) == false) return candidate; /*default resolver...keep trying but remember it in case none else be found*/ } return candidate; }
public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty) { var collectionContext = context.Nested(sourceProperty, destinationProperty); var src = (IList)context.GetSourcePropertyValue(sourceProperty.Name); var dest = (IList)activate.CreateCollectionInstance(destinationProperty.PropertyType, src.Count); for (int i = 0; i < src.Count; i++) { var sourceElement = sourceProperty.ElementAt(i); var elementContext = collectionContext.Nested(sourceElement, destinationProperty.ElementAt(i)); var nestedExecutor = this.executor.CreateExecutableMapping(sourceElement.PropertyType); nestedExecutor.Execute(elementContext); dest.AddElement(elementContext.Destination, i); } return(new Result(true, dest)); }
private IResolveValue TryGetCandidate(IDescribeMappableProperty mappableProperty) { IResolveValue candidate = null; foreach (var container in containers) { if (container.WillResolve(mappableProperty) == false) { continue; } IContainResolvers copy = container; candidate = copy.GetResolver(mappableProperty); if (typeof(IOverrideable).IsInstanceOfType(candidate) == false) { return(candidate); } /*default resolver...keep trying but remember it in case none else be found*/ } return(candidate); }
public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty) { /* * Like its name implies, this container will match the first resolver that 'WillResolve'. * If the resolver is IOverrideable it will try to continue to the next resolver that WillResolve, returning that candidate if none else is found. * This means the ordering is imporant in the construction of this resolver. */ IResolveValue candidate; if (cachedResolvers.TryGetValue(destinationProperty, out candidate)) return candidate; candidate = TryGetCandidate(destinationProperty); if (candidate != null) { cachedResolvers.Add(destinationProperty,candidate); return candidate; } throw new InvalidOperationException("This container does not having any matching resolvers for '" + destinationProperty + "'"); }
public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty) { /* * Like its name implies, this container will match the first resolver that 'WillResolve'. * If the resolver is IOverrideable it will try to continue to the next resolver that WillResolve, returning that candidate if none else is found. * This means the ordering is imporant in the construction of this resolver. */ IResolveValue candidate; if (cachedResolvers.TryGetValue(destinationProperty, out candidate)) { return(candidate); } candidate = TryGetCandidate(destinationProperty); if (candidate != null) { cachedResolvers.Add(destinationProperty, candidate); return(candidate); } throw new InvalidOperationException("This container does not having any matching resolvers for '" + destinationProperty + "'"); }
public bool HasResolverFromOtherSource(Type destinationType, IDescribeMappableProperty destinationProperty) { return destinationType != SourceType && WillResolve(destinationProperty); }
public bool IsSatisfiedBy(IDescribeMappableProperty property) { return property.PropertyType.IsOneOf(targetType); }
public bool WillResolve(IDescribeMappableProperty destinationProperty) { return inner.WillResolve(destinationProperty); }
public ListResolver(IDescribeMappableProperty sourceProperty, ICreateExecutableMapping executor, IActivate activate) { this.sourceProperty = sourceProperty; this.executor = executor; this.activate = activate; }
public bool IsSatisfiedBy(IDescribeMappableProperty property) { return anotherConfiguration.DestinationType == property.PropertyType; }
public ResolverContext(IDescribeMappableProperty sourceProperty, IDescribeMappableProperty destinationProperty, ICreateExecutableMapping configuration) { DestinationProperty = destinationProperty; SourceProperty = sourceProperty; Configuration = configuration; }
public Convention(IDescribeMappableProperty[] destinationProperties, IResolveValue resolver) { this.destinationProperties = destinationProperties; this.resolver = resolver; }
public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty) { if (WillResolve(destinationProperty) == false) throw new InvalidOperationException("Resolver not configured for " + destinationProperty); return resolver; }
public bool HasResolverFromOtherSource(Type destinationType, IDescribeMappableProperty destinationProperty) { //really this shouldn't matter return false; }
public bool WillResolve(IDescribeMappableProperty destinationProperty) { return destinationProperties.Any(are => string.Equals(are.Name,destinationProperty.Name)); }
public void Visit(IDescribeMappableProperty mappableProperty) { cache.CacheSet(mappableProperty.DeclaringType, mappableProperty.Name); }