Example #1
0
 public static void AssertInstanceDerivesFromOrEqual(object instance, Type baseType)
 {
     if (!ZenUtilInternal.IsNull(instance))
     {
         Assert.That(instance.GetType().DerivesFromOrEqual(baseType),
                     "Invalid type given during bind command.  Expected type '{0}' to derive from type '{1}'", instance.GetType(), baseType.Name());
     }
 }
Example #2
0
        public static void AssertIsValidGameObject(GameObject gameObject)
        {
            Assert.That(!ZenUtilInternal.IsNull(gameObject), "Received null game object during bind command");

#if UNITY_EDITOR
            Assert.That(PrefabUtility.GetPrefabType(gameObject) != PrefabType.Prefab,
                        "Expected game object but found prefab instead with name '{0}' during bind command", gameObject.name);
#endif
        }
Example #3
0
 public static void AssertInstanceDerivesFromOrEqual(object instance, IEnumerable <Type> parentTypes)
 {
     if (!ZenUtilInternal.IsNull(instance))
     {
         foreach (var baseType in parentTypes)
         {
             AssertInstanceDerivesFromOrEqual(instance, baseType);
         }
     }
 }
Example #4
0
        public static void AssertIsValidPrefab(UnityEngine.Object prefab)
        {
            Assert.That(!ZenUtilInternal.IsNull(prefab), "Received null prefab during bind command");

//#if UNITY_EDITOR
//            // This won't execute in dll builds sadly
//            Assert.That(PrefabUtility.GetPrefabType(prefab) == PrefabType.Prefab,
//                "Expected prefab but found game object with name '{0}' during bind command", prefab.name);
//#endif
        }
Example #5
0
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hash = 17;
         hash = hash * 29 + (this.ConcreteIdentifier == null ? 0 : this.ConcreteIdentifier.GetHashCode());
         hash = hash * 29 + (ZenUtilInternal.IsNull(this.Prefab) ? 0 : this.Prefab.GetHashCode());
         return(hash);
     }
 }
Example #6
0
        public static void AssertIsValidGameObject(GameObject gameObject)
        {
            Assert.That(!ZenUtilInternal.IsNull(gameObject), "Received null game object during bind command");

#if UNITY_EDITOR
            // Unfortunately we can't do this check because asset bundles return PrefabType.None here
            // as discussed here: https://github.com/modesttree/Zenject/issues/269#issuecomment-323419408
            //Assert.That(PrefabUtility.GetPrefabType(gameObject) != PrefabType.Prefab,
            //"Expected game object but found prefab instead with name '{0}' during bind command", gameObject.name);
#endif
        }
        public static void AssertIsValidPrefab(UnityEngine.Object prefab)
        {
            Assert.That(!ZenUtilInternal.IsNull(prefab), "Received null prefab during bind command");

#if UNITY_EDITOR
            // Unfortunately we can't do this check because asset bundles return PrefabType.None here
            // as discussed here: https://github.com/svermeulen/Zenject/issues/269#issuecomment-323419408
            //Assert.That(PrefabUtility.GetPrefabType(prefab) == PrefabType.Prefab,
            //"Expected prefab but found game object with name '{0}' during bind command", prefab.name);
#endif
        }
Example #8
0
        protected ScopeBinder FromInstanceBase(object instance, bool allowNull)
        {
            if (!allowNull)
            {
                Assert.That(!ZenUtilInternal.IsNull(instance),
                            "Found null instance for type '{0}' in FromInstance method",
                            ConcreteTypes.First().Name());
            }

            BindingUtil.AssertInstanceDerivesFromOrEqual(instance, AllParentTypes);

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo, SingletonTypes.ToInstance, instance,
                (container, type) => new InstanceProvider(container, type, instance));

            return(new ScopeBinder(BindInfo));
        }