// we can't have this method because of the necessary where() below, so in this case they have to specify TContract twice //public BindingConditionSetter ToSingle(GameObject prefab) // Note: Here we assume that the contract is a component on the given prefab public BindingConditionSetter ToSingleFromPrefab <TConcrete>(GameObject prefab) where TConcrete : Component, TContract { if (UnityUtil.IsNull(prefab)) { throw new ZenjectBindException("Received null prefab while binding type '{0}'".With(typeof(TConcrete).Name())); } return(ToProvider(_singletonMap.CreateProviderFromPrefab <TConcrete>(prefab))); }
// Note: Here we assume that the contract is a component on the given prefab public BindingConditionSetter ToSingleFromPrefab <TConcrete>(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}'".With(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}'".With(concreteType.Name())); } return(ToProvider(_singletonMap.CreateProviderFromPrefab(typeof(TConcrete), prefab))); }