I have created Signal command binder in generic way

33 views
Skip to first unread message

krishna...@juegostudio.net

unread,
Sep 11, 2018, 4:44:46 AM9/11/18
to StrangeIoC
Hello, i am doing another di framework from the experience of strange. i have made generic way for signal command binder. so now this wont give any GC in update. :::)))

var gtype = this.GetType();
methodZero = gtype.GetMethod("GenericCommandZero", flags);
methodOne = gtype.GetMethod("GenericCommandOne", flags);
methodTwo = gtype.GetMethod("GenericCommandTwo", flags);
methodThree = gtype.GetMethod("GenericCommandThree", flags);
methodFour = gtype.GetMethod("GenericCommandFour", flags);
 
 
private void GenericCommandZero(IBaseSignal signal)
        {
            var command = getCommand(signal.GetType());
            (command as Command).Execute();
        }

        private void GenericCommandOne<T>(IBaseSignal signal, T type1)
        {
            var command = getCommand(signal.GetType());
            (command as Command<T>).Execute(type1);
        }

        private void GenericCommandTwo<T, U>(IBaseSignal signal, T type1, U type2)
        {
            var command = getCommand(signal.GetType());
            (command as Command<T, U>).Execute(type1, type2);
        }

        private void GenericCommandThree<T, U, V>(IBaseSignal signal, T type1, U type2, V type3)
        {
            var command = getCommand(signal.GetType());
            (command as Command<T, U, V>).Execute(type1, type2, type3);
        }

        private void GenericCommandFour<T, U, V, W>(IBaseSignal signal)
        {
            var command = getCommand(signal.GetType());
            var bs = signal as BaseSignal<T, U, V, W>; // exception case
            (command as Command<T, U, V, W>).Execute(bs.Type1, bs.Type2, bs.Type3, bs.Type4);
        }
  

private MethodInfo getGenericMethod(Type key)
        {
            var binding = GetBinding(key);
            var type = binding.Key.BaseType;
            if (type.IsGenericType)
            {
                var gParams = type.GetGenericArguments();
                var signal = injectionBinder.GetInstance(binding.Key);
                switch (gParams.Length)
                {
                    case 1:
                        return methodOne.MakeGenericMethod(gParams);
                    case 2:
                        return methodTwo.MakeGenericMethod(gParams);
                    case 3:
                        return methodThree.MakeGenericMethod(gParams);
                    case 4:
                        return methodFour.MakeGenericMethod(gParams);
                }
            }

            return methodZero;
        }
  



like this. 
Reply all
Reply to author
Forward
0 new messages