public CompositionContext() { //foreach (var mut in Mutators.Get(t)) mut(val); Singletons = new Dictionary <Type, object>(); Factories = new TypedFactory(); Factories.Mutate((t, o) => { foreach (var mut in Mutators.Get(t)) { mut(o); } }); TaggedFactories = new FactoryDictionary <Type, TypedFactory>(); TaggedFactories.Loader((t) => { var fac = new TypedFactory(); fac.Mutate((t2, o) => { foreach (var mut in TaggedMutators.Get(t).Get(t2)) { mut(o); } }); return(fac); }); Mutators = new FactoryDictionary <Type, IList <Action <object> > >(); Mutators.Loader((t) => new List <Action <object> >()); TaggedMutators = new FactoryDictionary <Type, FactoryDictionary <Type, IList <Action <object> > > >(); TaggedMutators.Loader((t) => { var muts = new FactoryDictionary <Type, IList <Action <object> > >(); muts.Loader((t2) => new List <Action <object> >()); return(muts); }); }
private Dictionary <string, string> GetMutatedProofKeyHeaders( Dictionary <string, string> original, Func <long, Dictionary <string, string> > proofKeyGeneration) { ProofKeyMutator mutator = Mutators.OfType <ProofKeyMutator>().FirstOrDefault(); return(mutator == null ? original : mutator.Mutate(original, proofKeyGeneration)); }
/// <summary> /// Mutate a <see cref="MonoBehaviour"/> in a <see cref="Context"/> before it gets injected. /// </summary> /// <typeparam name="T">The type of the <see cref="MonoBehaviour"/>.</typeparam> /// <param name="action">The callback to handle mutations in.</param> public InstallBuilder Mutate <T>(Action <MutationContext, T> action) where T : MonoBehaviour { if (action == null) { return(this); } Mutators.Add(new Tuple <Type, DelegateWrapper>(typeof(T), new DelegateWrapper().Wrap(action))); return(this); }
internal static Func <TPostMutate, TPreMutate> GetResponseMutator(string propertyName) { if (!Mutators.TryGetValue(propertyName, out var mutator)) { return(null); } return(mutator.OnResponse); }
public void Mutate <T>(T affair) where T : Affair { var methodName = Mutators.Single(m => m.Key == typeof(T)).Value; if (methodName is null) { throw new InvalidMutationException($"No registered method found for {nameof(T)}."); } var method = GetType().Method(methodName, new[] { typeof(T) }, Flags.InstancePrivate); method.Invoke(this, new[] { affair }); }
public static void SetMutator(string properyName, Func <TPreMutate, TPostMutate> onRequest, Func <TPostMutate, TPreMutate> onResponse) { var mutationObj = new MutationObject <TPreMutate, TPostMutate> { OnRequest = onRequest, OnResponse = onResponse }; if (!Mutators.ContainsKey(properyName)) { PropertiesToMutate.Add(properyName); Mutators.Add(properyName, mutationObj); return; } Mutators[properyName] = mutationObj; }
private string GetMutatedAccessToken(string original) { AccessTokenMutator mutator = Mutators.OfType <AccessTokenMutator>().FirstOrDefault(); return(mutator == null ? original : mutator.Mutate(original)); }
private IEnumerable <Mutant> FindMutants(SyntaxNode current, MutationContext context) { return(Mutators.SelectMany(mutator => ApplyMutator(current, mutator, context))); }
private void RegisterMutatorsInternal() { Mutators.Add(typeof(AggregateCreated), nameof(OnAggregateCreated)); RegisterMutators(Mutators); }