コード例 #1
0
        // Note that concreteType here could be an interface as well
        public BindingConditionSetter ToSinglePrefab(Type concreteType, string singletonIdentifier, GameObject prefab)
        {
            Assert.That(concreteType.DerivesFromOrEqual <TContract>());

            if (UnityUtil.IsNull(prefab))
            {
                throw new ZenjectBindException(
                          "Received null prefab while binding type '{0}'".Fmt(concreteType.Name()));
            }

            return(ToProvider(
                       _prefabSingletonMap.CreateProvider(singletonIdentifier, concreteType, prefab)));
        }
コード例 #2
0
ファイル: BinderUntyped.cs プロジェクト: hexgrimm/Zenject
        public BindingConditionSetter ToSingleFromPrefab <TConcrete>(string identifier, GameObject prefab)
            where TConcrete : Component
        {
            var concreteType = typeof(TConcrete);

            if (!concreteType.DerivesFromOrEqual(_contractType))
            {
                throw new ZenjectBindException(
                          "Invalid type given during bind command.  Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), _contractType.Name()));
            }

            // We have to cast to object otherwise we get SecurityExceptions when this function is run outside of unity
            if (UnityUtil.IsNull(prefab) && !_container.AllowNullBindings)
            {
                throw new ZenjectBindException("Received null prefab while binding type '{0}'".Fmt(concreteType.Name()));
            }

            return(ToProvider(_prefabSingletonMap.CreateProvider(identifier, typeof(TConcrete), prefab)));
        }