Beispiel #1
0
        public IEnumerable <Instance> Instantiate(IInstanceArgs args)
        {
            switch (args)
            {
            case DefaultInstanceArgs d: return(new[] { Instance.Default });

            case SingleVariableInstanceArgs s: return(Instantiate(s.Name, s.Resolver, args.Categories, args.Traits));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
        public void Build()
        {
            if (!isSetup)
            {
                throw new InvalidOperationException();
            }

            if (obj == InstanceSettlingXml.Unique)
            {
                args = new DefaultInstanceArgs();
            }

            else if ((obj as InstanceSettlingXml).Variable != null)
            {
                var variable = (obj as InstanceSettlingXml).Variable;

                var argsBuilder = new SequenceResolverArgsBuilder(serviceLocator);
                argsBuilder.Setup(settings);
                argsBuilder.Setup(globalVariables);
                argsBuilder.Setup(variable.Type);

                if (variable.SentinelLoop != null)
                {
                    argsBuilder.Setup(variable.SentinelLoop);
                }
                else if (variable.Items != null)
                {
                    argsBuilder.Setup(variable.Items);
                }
                else
                {
                    throw new ArgumentOutOfRangeException();
                }

                argsBuilder.Build();
                var factory = new SequenceResolverFactory(serviceLocator);

                args = new SingleVariableInstanceArgs()
                {
                    Name       = variable.Name,
                    Resolver   = factory.Instantiate(variable.Type, argsBuilder.GetArgs()),
                    Categories = (obj as InstanceSettlingXml).Categories,
                    Traits     = (obj as InstanceSettlingXml).Traits.ToDictionary(x => x.Name, x => x.Value),
                };
            }
        }