예제 #1
0
        private static bool InjectInternal(InjectionPoint injectionPoint, object subject, DependencyReference dependency,
                                           bool overrideExisting)
        {
            var isNameMatch = injectionPoint.Info.Name == null ||
                              injectionPoint.Info.Name.Equals(dependency.Name);
            var isTypeMatch = injectionPoint.Injector.Type.IsInstanceOfType(dependency.Instance) &&
                              injectionPoint.Injector.Info.DeclaringType.IsInstanceOfType(subject);
            var  currentValue = injectionPoint.Injector.GetValue(subject);
            bool isDependencyAlreadySet;

            if (currentValue is UnityEngine.Object)
            {
                isDependencyAlreadySet = (currentValue as UnityEngine.Object) != null;
            }
            else
            {
                isDependencyAlreadySet = currentValue != null;
            }

            if (isNameMatch && isTypeMatch && (!isDependencyAlreadySet || overrideExisting))
            {
                injectionPoint.Injector.SetValue(subject, dependency.Instance);
                return(true);
            }
            return(false);
        }
예제 #2
0
        private static bool IsDependencySet(InjectionPoint injectionPoint, object subject)
        {
            object storedValue = injectionPoint.Injector.GetValue(subject);

            if (storedValue is UnityEngine.Object)
            {
                return((storedValue as UnityEngine.Object) != null);
            }
            return(storedValue != null);
        }