private Boolean ProcessGenericTypeBindingFromPublicComposite(
            CompositeModel cModel,
            CollectionsFactory cf,
            Tuple <Type, Type> pcType,
            Type type,
            out ListProxy <AbstractGenericTypeBinding> result
            )
        {
            var retyrn = type.IsGenericParameter;

            if (retyrn)
            {
                result = cf.NewListProxy(new List <AbstractGenericTypeBinding>());
            }
            else
            {
                var array = type.GetGenericArguments().Select(t =>
                {
                    AbstractGenericTypeBinding gtb = null;
                    var gIdx    = Array.IndexOf(pcType.Item1.GetGenericArguments(), t);
                    var retyrn2 = !t.IsGenericParameter || gIdx != -1;
                    if (retyrn2)
                    {
                        if (t.IsGenericParameter)
                        {
                            var state = new IndirectGenericTypeBindingState();
                            state.GenericDefinition = cModel.PublicTypes.First(pt => pt.GetAllParentTypes().Select(ptt => ptt.GetGenericDefinitionIfGenericType()).Any(ptt => ptt.Equals(pcType.Item2.GetGenericDefinitionIfGenericType())));
                            state.GenericIndex      = gIdx;
                            gtb = new IndirectGenericTypeBindingImpl(state);
                        }
                        else
                        {
                            var state  = new DirectGenericTypeBindingState();
                            state.Type = t;
                            retyrn2    = this.ProcessGenericTypeBindingFromPublicComposite(cModel, cf, pcType, t, out state._innerBindings);
                            gtb        = new DirectGenericTypeBindingImpl(state);
                        }
                    }
                    else
                    {
                    }
                    return(Tuple.Create(retyrn2, gtb));
                }).ToArray();
                retyrn = array.Count(tuple => tuple.Item1) == type.GetGenericArguments().Length;
                if (retyrn)
                {
                    result = cf.NewListProxy(array.Select(a => a.Item2).ToList());
                }
                else
                {
                    result = null;
                }
            }
            return(retyrn);
        }
        private Boolean ProcessGenericTypeBindingFromPrivateComposite(
            CompositeModel cModel,
            CollectionsFactory cf,
            Type pcType,
            Type type,
            ListQuery <AbstractGenericTypeBinding> currentPrivateCompositeBindings,
            out ListProxy <AbstractGenericTypeBinding> result
            )
        {
            var retyrn = type.IsGenericParameter;

            if (retyrn)
            {
                result = cf.NewListProxy(new List <AbstractGenericTypeBinding>());
            }
            else
            {
                var array = type.GetGenericArguments().Select(t =>
                {
                    AbstractGenericTypeBinding gtb = null;
                    Boolean retyrn2;
                    if (t.IsGenericParameter)
                    {
                        var stk = new Stack <Type>();
                        retyrn2 = false;
                        // Use DFS to search generic arguments and find binding to public composite
                        // TODO replace this code with .AsDepthFirstIEnumerable()
                        var gArgs = pcType.GetGenericArguments();
                        for (var i = 0; i < gArgs.Length; ++i)
                        {
                            stk.Push(gArgs[i]);
                            while (!retyrn2 && stk.Any())
                            {
                                var current = stk.Pop();
                                if (current.IsGenericParameter)
                                {
                                    if (t == current)
                                    {
                                        // We've found the correct one
                                        gtb     = currentPrivateCompositeBindings[i];
                                        retyrn2 = true;
                                    }
                                }
                                else if (current.IsGenericType())
                                {
                                    foreach (var ig in current.GetGenericArguments())
                                    {
                                        stk.Push(ig);
                                    }
                                }
                            }
                            if (retyrn2)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        var state  = new DirectGenericTypeBindingState();
                        state.Type = t;
                        retyrn2    = this.ProcessGenericTypeBindingFromPrivateComposite(cModel, cf, pcType, t, currentPrivateCompositeBindings, out state._innerBindings);
                        gtb        = new DirectGenericTypeBindingImpl(state);
                    }
                    return(Tuple.Create(retyrn2, gtb));
                }).ToArray();
                retyrn = array.Count(tuple => tuple.Item1) == type.GetGenericArguments().Length;
                if (retyrn)
                {
                    result = cf.NewListProxy(array.Select(a => a.Item2).ToList());
                }
                else
                {
                    result = null;
                }
            }
            return(retyrn);
        }