static void Main(string[] args) { var modules = new AbstractModule[] { new ModuleA(), new ModuleB() }; foreach (var module in modules) { module.TemplateMethod(); } Console.ReadKey(); }
public static void Time(this Stopwatch sw, Action action, object iterations, AbstractModule writeTo) { var iterCount = (int)iterations; writeTo.ClearMessage(); sw.Reset(); sw.Start(); for (int i = 0; i < iterCount; i++) { action(); } sw.Stop(); writeTo.Timing = sw.ElapsedMilliseconds.ToString(); }
public static UIElement CreateTimedButton(MemberInfo methodToLink, object bindingObject, Dictionary <string, object> options = null) { var e = new System.Windows.Controls.Button(); AbstractModule m = options["currentModule"] as AbstractModule; Action del = (Action)Delegate.CreateDelegate(typeof(Action), bindingObject, methodToLink as MethodInfo); e.Click += (o, i) => TimedAction(del, m, m.Iterations).Invoke(); e.Content = methodToLink.Name; return(e); // Lokale Methode: "Wrappt" die zu ausführende Methode mit einer Stopwatch und erlaubt es X iterationen durchzuführen Action TimedAction(Action a, AbstractModule target, object iter) { var s = new Stopwatch(); return(new Action(() => s.Time(() => a(), iter, target))); } }
public static async Task TimeAsync(this Stopwatch sw, Func <Task> action, object iterations, AbstractModule writeTo) { var iterCount = (int)iterations; writeTo.ClearMessage(); sw.Reset(); sw.Start(); for (int i = 0; i < iterCount; i++) { await action(); } sw.Stop(); writeTo.Timing = sw.ElapsedMilliseconds.ToString(); }
public static string GetGrammarName(this AbstractModule Module) { return(Module.GetType().ToString()); }
public static IEndpointBuilder CreateBuilder(AbstractModule module, IEndpointRouteBuilder builder) { return((IEndpointBuilder) _createCoreMethod.MakeGenericMethod(module.GetType()) .Invoke(null, new object[] { module, builder }) !); }
public void RegisterModule(AbstractModule module) { module.Configure(); RegisterBindings(module.Bindings); CreateProvidersFromMethods(module); }
private void CreateProvidersFromMethods(AbstractModule module) { foreach (MethodInfo methodInfo in module.GetType().GetMethodsWithAttribute<Provides>()) { Provides provides = (Provides) Attribute.GetCustomAttribute(methodInfo, typeof (Provides)); Type[] dependencyTypes = methodInfo.GetParameters().Select(param => param.ParameterType).ToArray(); if (provides.Scope == Scope.NO_SCOPE) { RegisterProvider(methodInfo.ReturnType, new MethodProvider(module, methodInfo, dependencyTypes)); } else { RegisterProvider(methodInfo.ReturnType, new SingletonMethodProvider( provides.Scope, module, methodInfo, dependencyTypes)); } } }
public MethodProvider(AbstractModule module, MethodInfo methodInfo, Type[] dependencyTypes) : base(methodInfo.ReturnType, dependencyTypes) { this.module = module; this.methodInfo = methodInfo; }