Exemplo n.º 1
0
 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);
     });
 }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
 /// <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);
 }
Exemplo n.º 4
0
        internal static Func <TPostMutate, TPreMutate> GetResponseMutator(string propertyName)
        {
            if (!Mutators.TryGetValue(propertyName, out var mutator))
            {
                return(null);
            }

            return(mutator.OnResponse);
        }
Exemplo n.º 5
0
        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 });
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        private string GetMutatedAccessToken(string original)
        {
            AccessTokenMutator mutator = Mutators.OfType <AccessTokenMutator>().FirstOrDefault();

            return(mutator == null ? original : mutator.Mutate(original));
        }
Exemplo n.º 8
0
 private IEnumerable <Mutant> FindMutants(SyntaxNode current, MutationContext context)
 {
     return(Mutators.SelectMany(mutator => ApplyMutator(current, mutator, context)));
 }
Exemplo n.º 9
0
 private void RegisterMutatorsInternal()
 {
     Mutators.Add(typeof(AggregateCreated), nameof(OnAggregateCreated));
     RegisterMutators(Mutators);
 }