Beispiel #1
0
        public void OptionalHasValueDynamicChecks()
        {
            Optional.ApplyHasValueCondition <Base>(v => v.GetType() == typeof(A) || v.Threshold > 200); // Cheat: allow check if type A to do more complex tests on Optional<T>.HasValue
            Optional.ApplyHasValueCondition <A>(v => v.Threshold <= 200);

            Optional <A> a = Optional.Of(new A());

            a.HasValue.Should().BeTrue();

            Optional <A> actuallyB = Optional.Of <A>(new B());

            actuallyB.HasValue.Should().BeFalse();

            Optional <B> b = Optional.Of(new B());

            b.HasValue.Should().BeFalse();

            // A check should still happen on Base because Optional<Base> includes more-specific-than-itself checks.
            Optional <Base> aAsBase = Optional <Base> .Of((Base)a);

            aAsBase.HasValue.Should().BeTrue();

            // Optional<object> should always do all checks because anything can be in it.
            Optional <object> bAsObj = Optional <object> .Of(new B());

            bAsObj.HasValue.Should().BeFalse();

            // Type C inheritance doesn't allow for type A. But Optional<object> has the check on A. It should skip the A check on C because inheritance doesn't match up.
            Optional <object> cAsObj = Optional <object> .Of(new C());

            cAsObj.HasValue.Should().BeTrue();
        }
Beispiel #2
0
        private static void Initialize()
        {
            Optional.ApplyHasValueCondition <UnityEngine.Object>(o => (bool)o);

            if (container != null)
            {
                throw new Exception($"Patches have already been detected! Call {nameof(Apply)} or {nameof(Restore)} instead.");
            }
            Log.Info("Registering dependencies");
            container = CreatePatchingContainer();
            try
            {
                NitroxServiceLocator.InitializeDependencyContainer(new ClientAutoFacRegistrar());
            }
            catch (ReflectionTypeLoadException ex)
            {
                Log.Error($"Failed to load one or more dependency types for Nitrox. Assembly: {ex.Types.FirstOrDefault()?.Assembly.FullName ?? "unknown"}");
                foreach (Exception loaderEx in ex.LoaderExceptions)
                {
                    Log.Error(loaderEx);
                }
                throw;
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error while initializing and loading dependencies.");
                throw;
            }

            InitPatches();
            ApplyNitroxBehaviours();
        }
Beispiel #3
0
        public static void Execute()
        {
            Log.EnableInGameMessages();
            Optional.ApplyHasValueCondition <Object>(o => (bool)o);

            if (container != null)
            {
                Log.Warn("Patches have already been detected! Call Apply or Restore instead.");
                return;
            }

            Log.Info("Registering Dependencies");
            container = CreatePatchingContainer();
            NitroxServiceLocator.InitializeDependencyContainer(new ClientAutoFacRegistrar());

            InitPatches();
            ApplyNitroxBehaviours();
        }