예제 #1
0
        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);
 }
예제 #4
0
 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);
 }
예제 #6
0
        private bool IsCustomTypeAndCustomResolverSet(IDescribeMappableProperty prop)
        {
            var resolver = destinationProperty2Resolver[prop];

            return(prop.IsCustomType &&
                   typeof(RequiresComponentMappingResolver).IsInstanceOfType(resolver) == false &&
                   typeof(RequiresCollectionMappingResolver).IsInstanceOfType(resolver) == false);
        }
예제 #7
0
 public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty)
 {
     if (WillResolve(destinationProperty) == false)
     {
         throw new InvalidOperationException("Resolver not configured for " + destinationProperty);
     }
     return(resolver);
 }
예제 #8
0
 public IAssignValue BuildValueAssignment(IDescribeMappableProperty destinationProperty)
 {
     if (destinationProperty == null)
     {
         throw new ArgumentNullException("destinationProperty");
     }
     return(valueAssignments.Create(destination, destinationProperty));
 }
예제 #9
0
 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);
 }
예제 #11
0
 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);
 }
예제 #12
0
        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));
        }
예제 #13
0
 public NullSourceContext(IDescribeMappableProperty sourceProperty, ICreateValueAssignment valueAssignments, IInvoke invoke, IActivate activate)
 {
     this.valueAssignments = valueAssignments;
     this.invoke = invoke;
     this.activate = activate;
     SourceType = sourceProperty.PropertyType;
     Source = null;
 }
예제 #14
0
 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);
 }
예제 #15
0
 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);
     }
 }
예제 #17
0
 public Result TryResolve(IResolutionContext context, IDescribeMappableProperty destinationProperty)
 {
     if (sourced != null)
     {
         return(sourced.TryResolve(context, destinationProperty));
     }
     return(UsingReflection(context.SourceType, context.Source));
 }
예제 #18
0
 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));
 }
예제 #19
0
        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));
        }
예제 #20
0
        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)));
        }
예제 #21
0
 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;
 }
예제 #22
0
 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();
 }
예제 #23
0
        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);
        }
예제 #24
0
        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));
        }
예제 #25
0
        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);
        }
예제 #26
0
        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));
        }
예제 #27
0
        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));
        }
예제 #28
0
 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;
 }
예제 #29
0
        public bool WillResolve(IDescribeMappableProperty destinationProperty)
        {
            var container = inner as IContainResolvers;

            if (container == null)
            {
                return(false);
            }
            return(container.WillResolve(destinationProperty));
        }
예제 #30
0
 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);
 }
예제 #31
0
        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));
        }
예제 #32
0
        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);
        }
예제 #33
0
 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;
 }
예제 #34
0
 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();
 }
예제 #35
0
 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)));
 }
예제 #36
0
        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));
        }
예제 #37
0
 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));
 }
예제 #38
0
        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));
        }
예제 #39
0
 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));
 }
예제 #40
0
        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);
 }
예제 #42
0
        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)));
        }
예제 #43
0
        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));
        }
예제 #44
0
        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;
        }
예제 #46
0
        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 + "'");
        }
예제 #50
0
 public bool HasResolverFromOtherSource(Type destinationType, IDescribeMappableProperty destinationProperty)
 {
     return destinationType != SourceType && WillResolve(destinationProperty);
 }
예제 #51
0
 public bool IsSatisfiedBy(IDescribeMappableProperty property)
 {
     return property.PropertyType.IsOneOf(targetType);
 }
예제 #52
0
 public bool WillResolve(IDescribeMappableProperty destinationProperty)
 {
     return inner.WillResolve(destinationProperty);
 }
예제 #53
0
 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;
 }
예제 #55
0
 public ResolverContext(IDescribeMappableProperty sourceProperty, IDescribeMappableProperty destinationProperty, ICreateExecutableMapping configuration)
 {
     DestinationProperty = destinationProperty;
     SourceProperty      = sourceProperty;
     Configuration       = configuration;
 }
예제 #56
0
 public Convention(IDescribeMappableProperty[] destinationProperties, IResolveValue resolver)
 {
     this.destinationProperties = destinationProperties;
     this.resolver = resolver;
 }
예제 #57
0
 public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty)
 {
     if (WillResolve(destinationProperty) == false)
         throw new InvalidOperationException("Resolver not configured for " + destinationProperty);
     return resolver;
 }
예제 #58
0
 public bool HasResolverFromOtherSource(Type destinationType, IDescribeMappableProperty destinationProperty)
 {
     //really this shouldn't matter
     return false;
 }
예제 #59
0
 public bool WillResolve(IDescribeMappableProperty destinationProperty)
 {
     return destinationProperties.Any(are => string.Equals(are.Name,destinationProperty.Name));
 }
예제 #60
0
 public void Visit(IDescribeMappableProperty mappableProperty)
 {
     cache.CacheSet(mappableProperty.DeclaringType, mappableProperty.Name);
 }