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"); }
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>())); }
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); }
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"); }
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"); }
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);
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); } }); }
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); } }
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; } }
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()); }
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); }
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); } } }