Exemplo n.º 1
0
        public GameObjectNameGroupNameScopeArgBinder FromGameObject()
        {
            BindingUtil.AssertIsAbstractOrComponentOrGameObject(BindInfo.ContractTypes);
            BindingUtil.AssertIsComponentOrGameObject(ConcreteTypes);

            var gameObjectInfo = new GameObjectCreationParameters();

            if (ConcreteTypes.All(x => x == typeof(GameObject)))
            {
                SubFinalizer = new ScopableBindingFinalizer(
                    BindInfo, SingletonTypes.ToGameObject, gameObjectInfo,
                    (container, type) =>
                {
                    Assert.That(BindInfo.Arguments.IsEmpty(), "Cannot inject arguments into empty game object");
                    return(new EmptyGameObjectProvider(
                               container, gameObjectInfo));
                });
            }
            else
            {
                BindingUtil.AssertIsComponent(ConcreteTypes);
                BindingUtil.AssertTypesAreNotAbstract(ConcreteTypes);

                SubFinalizer = new ScopableBindingFinalizer(
                    BindInfo, SingletonTypes.ToGameObject, gameObjectInfo,
                    (container, type) => new AddToNewGameObjectComponentProvider(
                        container,
                        type,
                        BindInfo.ConcreteIdentifier,
                        BindInfo.Arguments,
                        gameObjectInfo));
            }

            return(new GameObjectNameGroupNameScopeArgBinder(BindInfo, gameObjectInfo));
        }