예제 #1
0
        public void TestMethodProxy_BoolParam()
        {
            var d = new Data {
                fieldPrimitive = 42, propertyPrimitive = 3.14
            };
            var mi    = typeof(Data).GetMethod("GetPrimitiveValue");
            var proxy = new MethodProxy(mi);

            var s = proxy.Invoke(d, new object[] { true });

            Assert.AreEqual("42", s, "Bad Conversion");

            s = proxy.Invoke(d, new object[] { false });
            Assert.AreEqual("3.14", s, "Bad Conversion");
        }
예제 #2
0
        public object Main(Dictionary <string, object> args)
        {
            if (lake == null)
            {
                throw new System.InvalidOperationException("Lake has not been inject!");
            }
            var methodProxy = new MethodProxy(this, this.FindEntryPoint(), lake + GetSepLake(args));

            return(methodProxy.Invoke(args ?? new Dictionary <string, object>()));
        }
예제 #3
0
        public void CustomArgsTest()
        {
            MethodProxy maxProxy = new MethodProxy(this, nameof(Max), LakeExtension.Empty);
            var         args     = new Dictionary <string, object>()
            {
                { "x", 1 }, { "y", 2 }
            };
            int result = (int)maxProxy.Invoke(args);

            Assert.IsTrue(result == 2);
        }
예제 #4
0
        public void TestMethodProxy_VoidFn()
        {
            var d     = new Data();
            var mi    = typeof(Data).GetMethod("InitFieldPrimitive");
            var proxy = new MethodProxy(mi);

            Assert.AreEqual(0, d.fieldPrimitive, "Should be default value");
            var s = proxy.Invoke(d, new object[0]);

            Assert.IsNull(s, "retval should be null");
            Assert.AreEqual(69, d.fieldPrimitive, "Should have been set");
        }
예제 #5
0
        public void TestMethodProxy_NoParams()
        {
            var d = new Data {
                fieldObject = "Hi"
            };
            var mi    = typeof(Data).GetMethod("GetFieldObject");
            var proxy = new MethodProxy(mi);

            var s = proxy.Invoke(d, new object[0]);

            Assert.AreEqual("Hi", s, "Bad Conversion");
        }
예제 #6
0
        public object?Main(Dictionary <string, object> args)
        {
            if (lake == null)
            {
                throw new InvalidOperationException("Lake has not been inject!");
            }
            var methodProxy = new MethodProxy(this, this.FindEntryPoint(), lake + GetSepLake(args));

            try
            {
                return(methodProxy.Invoke(args ?? new Dictionary <string, object>()));
            }
            catch (TargetInvocationException e) when(e.InnerException?.GetType() == typeof(LeafUIExtension.LeafExtensionTerminatedException))
            {
                return(default);
예제 #7
0
 private void RunRoutines <T>()
 {
     Task.Run(() =>
     {
         try
         {
             var instance = new ObjectBuilder(typeof(T), Lake).Build();
             var mProxy   = new MethodProxy(instance, ROUTINE_DO_METHOD_NAME, Lake);
             mProxy.Invoke();
         }
         catch (Exception e)
         {
             SLogger <EssentialsLibrarin> .Warn("Routine is failed", e);
         }
     });
 }
예제 #8
0
        public override void RunTest()
        {
            var parms = new object[1];

            // The default test does nothing but give a baseline of how much the overhead costs.
            while (!StopRunning)
            {
                parms[0] = Iterations;
                var x = (long)m_proxy.Invoke(this, parms);

                if (Iterations != x)
                {
                    throw new InvalidOperationException();
                }
                System.Threading.Interlocked.Increment(ref Iterations);
            }
        }
예제 #9
0
        public object?Main(Dictionary <string, object> args)
        {
            if (lake == null)
            {
                throw new InvalidOperationException("Lake has not been inject!");
            }
            var methodProxy = new MethodProxy(this, this.FindEntryPoint(), lake + GetSepLake(args));

            try
            {
                return(methodProxy.Invoke(args ?? new Dictionary <string, object>()));
            }
            catch (TargetInvocationException e)
            {
                throw e.InnerException;
            }
        }
예제 #10
0
 public void Load()
 {
     for (int i = 0; i < stepMethods.Count(); i++)
     {
         try
         {
             Logger.Info($"Loading: {stepMethods.ElementAt(i).Name}()");
             var methodProxy = new MethodProxy(this, stepMethods.ElementAt(i), App.Current.Lake);
             methodProxy.Invoke();
             StepFinished?.Invoke(this, new StepFinishedEventArgs((uint)i, (uint)stepMethods.Count()));
         }
         catch (Exception e)
         {
             OnError("Uncaught error", new AppLoadingException(stepMethods.ElementAt(i).Name, e));
             return;
         }
     }
     Logger.Info("Done!");
     Succeced?.Invoke(this, new EventArgs());
 }
예제 #11
0
        public void MixArgsTest()
        {
            const string TEST_STR = "test string";
            const int    SUM      = 3;
            SunsetLake   lake     = new SunsetLake();

            lake.RegisterSingleton <string>("f**k");

            SunsetLake lake2 = new SunsetLake();

            lake.RegisterSingleton <string>(TEST_STR);

            MethodProxy maxProxy = new MethodProxy(this, nameof(HashCodeAdd), lake + lake2);
            long        result   = (long)maxProxy.Invoke(new Dictionary <string, object>()
            {
                { "x", 3 }
            });
            long correctResult = HashCodeAdd(SUM, TEST_STR);

            Assert.IsTrue(correctResult == result);
        }
예제 #12
0
        private void Register(ComponentAttribute attr, MethodInfo method)
        {
            var methodProxy = new MethodProxy(instance, method, registerableLake);

            object factory()
            {
                try
                {
                    return(methodProxy.Invoke());
                }
                catch (ShouldAutoCreateException e)
                {
                    return(new ObjectBuilder(e.T, registerableLake).Build());
                }
            }

            if (attr.SingletonMode)
            {
                if (attr.Id == null)
                {
                    registerableLake.RegisterSingleton(method.ReturnType, factory);
                }
                else
                {
                    registerableLake.RegisterSingleton(attr.Id, factory);
                }
            }
            else
            {
                if (attr.Id == null)
                {
                    registerableLake.Register(method.ReturnType, factory);
                }
                else
                {
                    registerableLake.Register(attr.Id, factory);
                }
            }
        }