示例#1
0
        private object ResolveArgument(DefaultNode toCreate, IUnresolvedArgument argument)
        {
            switch (argument.ArgumentType)
            {
            case UnresolvedArgumentType.Type:
                if (argument.IsMultipleResult)
                {
                    var value = (Array)Activator.CreateInstance(argument.MultipleResultElementType.MakeArrayType(), new object[] { argument.PlannedTargets.Length });
                    for (int index = 0; index < argument.PlannedTargets.Length; index++)
                    {
                        var target = argument.PlannedTargets[index];

                        if (target.Planned)
                        {
                            throw new ActivationException(
                                      "Expected " + target.FullName + " to be resolved by now.", toCreate);
                        }

                        value.SetValue(((DefaultNode)target).UntypedValue, index);
                    }
                    return(value);
                }
                else
                {
                    if (argument.PlannedTarget.Planned)
                    {
                        if (argument.IsOptional)
                        {
                            return(null);
                        }
                        else
                        {
                            throw new ActivationException(
                                      "Expected " + argument.PlannedTarget.FullName + " to be resolved by now.", toCreate);
                        }
                    }
                    return(((DefaultNode)argument.PlannedTarget).UntypedValue);
                }

            case UnresolvedArgumentType.Factory:
                return(argument.FactoryDelegate);

            case UnresolvedArgumentType.FactoryArgument:
                return(argument.FactoryArgumentValue);

            case UnresolvedArgumentType.CurrentNode:
                return(argument.CurrentNode);

            case UnresolvedArgumentType.KnownValue:
                return(argument.KnownValue);
            }

            throw new ActivationException("Unexpected argument type", toCreate);
        }
示例#2
0
        public INode CreateEmptyNode(string name, INode parent = null)
        {
            var node = new DefaultNode
            {
                Parent = parent,
                Name   = DefaultNode.NormalizeName(name)
            };

            if (parent == null)
            {
                _hierarchy.AddRootNode(node);
            }
            else
            {
                _hierarchy.AddChildNode(parent, node);
            }
            return(node);
        }
示例#3
0
        public INode CreateEmptyNode(string name, INode parent = null)
        {
            var node = new DefaultNode
            {
                Parent = parent,
                Name   = DefaultNode.NormalizeName(name)
            };

            if (parent == null)
            {
                _hierarchy.RootNodes.Add(node);
            }
            else
            {
                var childrenInternal = ((DefaultNode)parent).ChildrenInternal;
                if (!childrenInternal.Contains(node))
                {
                    childrenInternal.Add(node);
                }
            }
            return(node);
        }
示例#4
0
        private object ResolveArgument(DefaultNode toCreate, IUnresolvedArgument argument)
#endif
        {
            switch (argument.ArgumentType)
            {
            case UnresolvedArgumentType.Type:
                if (argument.IsMultipleResult)
                {
#if !PLATFORM_UNITY
                    var value = (Array)Activator.CreateInstance(argument.MultipleResultElementType.MakeArrayType(), new object[] { argument.PlannedTargets.Length });
                    for (int index = 0; index < argument.PlannedTargets.Length; index++)
#else
                    var value = (Array)Activator.CreateInstance(argument.MultipleResultElementType.MakeArrayType(), new object[] { argument.PlannedTargets.Count });
                    for (int index = 0; index < argument.PlannedTargets.Count; index++)
#endif
                    {
                        var target = argument.PlannedTargets[index];

                        while (target.Deferred && target.DeferredResolvedTarget != null)
                        {
                            target = target.DeferredResolvedTarget;
                        }

                        if (target.Planned)
                        {
                            throw new ActivationException(
                                      "Expected " + target.FullName + " to be resolved by now.", toCreate);
                        }

                        value.SetValue(((DefaultNode)target).UntypedValue, index);
                    }
                    return(value);
                }
                else
                {
                    var target = argument.PlannedTarget;

                    while (target.Deferred && target.DeferredResolvedTarget != null)
                    {
                        target = target.DeferredResolvedTarget;
                    }

                    if (target.Planned)
                    {
                        if (argument.InjectionParameters.OfType <OptionalAttribute>().Any())
                        {
                            return(null);
                        }
                        else
                        {
                            throw new ActivationException(
                                      "Expected " + target.FullName + " to be resolved by now.", toCreate);
                        }
                    }
                    return(((DefaultNode)target).UntypedValue);
                }

            case UnresolvedArgumentType.Factory:
                return(argument.FactoryDelegate);

            case UnresolvedArgumentType.FactoryArgument:
                return(argument.FactoryArgumentValue);

            case UnresolvedArgumentType.CurrentNode:
                return(argument.CurrentNode);

            case UnresolvedArgumentType.Node:
                return(argument.Node);

            case UnresolvedArgumentType.Hierarchy:
                return(argument.Hierarchy);

            case UnresolvedArgumentType.KnownValue:
                return(argument.KnownValue);
            }

            throw new ActivationException("Unexpected argument type", toCreate);
        }
示例#5
0
 private async Task <object> ResolveArgument(DefaultNode toCreate, IUnresolvedArgument argument)