Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 6
0
        private bool IsCustomTypeAndCustomResolverSet(IDescribeMappableProperty prop)
        {
            var resolver = destinationProperty2Resolver[prop];

            return(prop.IsCustomType &&
                   typeof(RequiresComponentMappingResolver).IsInstanceOfType(resolver) == false &&
                   typeof(RequiresCollectionMappingResolver).IsInstanceOfType(resolver) == false);
        }
Esempio n. 7
0
 public IResolveValue GetResolver(IDescribeMappableProperty destinationProperty)
 {
     if (WillResolve(destinationProperty) == false)
     {
         throw new InvalidOperationException("Resolver not configured for " + destinationProperty);
     }
     return(resolver);
 }
Esempio n. 8
0
 public IAssignValue BuildValueAssignment(IDescribeMappableProperty destinationProperty)
 {
     if (destinationProperty == null)
     {
         throw new ArgumentNullException("destinationProperty");
     }
     return(valueAssignments.Create(destination, destinationProperty));
 }
Esempio n. 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);
 }
 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);
 }
Esempio n. 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));
        }
Esempio n. 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;
 }
Esempio n. 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);
 }
Esempio n. 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);
     }
 }
Esempio n. 17
0
 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));
        }
Esempio n. 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)));
        }
Esempio n. 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;
 }
Esempio n. 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();
 }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 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;
 }
Esempio n. 29
0
        public bool WillResolve(IDescribeMappableProperty destinationProperty)
        {
            var container = inner as IContainResolvers;

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