Class that performs the generation of duck proxy types for forwarding delegate calls.
Exemplo n.º 1
0
        /// <summary>
        /// Gets the DelegateDuckProxyType object for a given duck type.
        /// </summary>
        /// <param name="toType">Type to be casted to.</param>
        /// <param name="fromType">Type of delegate to be casted.</param>
        /// <returns>The duck proxy type to use to cast or prepare for casting.</returns>
        private static DelegateDuckProxyType GetProxyType(Type toType, Type fromType)
        {
            DelegateDuckProxyType proxyType = null;

            FromTypeTree <DelegateDuckProxyType> fromTypeTree = null;

            if (s_ProxyTypeTree.ContainsKey(toType))
            {
                fromTypeTree = s_ProxyTypeTree[toType];

                if (fromTypeTree.ContainsKey(fromType))
                {
                    proxyType = fromTypeTree[fromType];
                }
            }

            if (proxyType == null)
            {
                proxyType = new DelegateDuckProxyType(toType, fromType);

                if (proxyType.CanProxy())
                {
                    if (fromTypeTree == null)
                    {
                        fromTypeTree = new FromTypeTree <DelegateDuckProxyType>();
                        s_ProxyTypeTree.Add(toType, fromTypeTree);
                    }

                    fromTypeTree.Add(fromType, proxyType);
                }
            }

            return(proxyType);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the DelegateDuckProxyType object for a given duck type.
        /// </summary>
        /// <param name="toType">Type to be casted to.</param>
        /// <param name="fromType">Type of delegate to be casted.</param>
        /// <returns>The duck proxy type to use to cast or prepare for casting.</returns>
        private static DelegateDuckProxyType GetProxyType(Type toType, Type fromType)
        {
            DelegateDuckProxyType proxyType = null;

            FromTypeTree<DelegateDuckProxyType> fromTypeTree = null;
            if (s_ProxyTypeTree.ContainsKey(toType))
            {
                fromTypeTree = s_ProxyTypeTree[toType];

                if (fromTypeTree.ContainsKey(fromType))
                {
                    proxyType = fromTypeTree[fromType];
                }
            }

            if (proxyType == null)
            {
                proxyType = new DelegateDuckProxyType(toType, fromType);

                if (proxyType.CanProxy())
                {
                    if (fromTypeTree == null)
                    {
                        fromTypeTree = new FromTypeTree<DelegateDuckProxyType>();
                        s_ProxyTypeTree.Add(toType, fromTypeTree);
                    }

                    fromTypeTree.Add(fromType, proxyType);
                }
            }

            return proxyType;
        }