Esempio n. 1
0
        /// <summary>
        /// Gets the implementation.
        /// </summary>
        /// <param name="methodID">The method identifier.</param>
        /// <param name="dynamicInfo">The dynamic information.</param>
        /// <param name="alternativeImplementer">The alternative implementer.</param>
        /// <returns>MethodID.</returns>
        /// <inheritdoc />
        public override MethodID GetImplementation(MethodID methodID, TypeDescriptor dynamicInfo, out TypeDescriptor alternativeImplementer)
        {
            alternativeImplementer = null;

            //get method implemented on type described by dynamicInfo
            var path = new PathInfo(dynamicInfo.TypeName);
            var node = GetTypeNode(path.Signature);

            if (node == null)
            {
                //type is not defined here
                return(null);
            }

            //only base type (not interfaces) could implement the method
            var implementingMethod = Naming.ChangeDeclaringType(dynamicInfo.TypeName, methodID, false);
            var item = getMethodItem(implementingMethod);

            if (item == null)
            {
                var baseType = node.Bases.Item(1) as CodeType;
                alternativeImplementer = InfoBuilder.CreateDescriptor(baseType);
                return(null);
            }

            return(item.Info.MethodID);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets identifier of implementing method for given abstract method.
        /// </summary>
        /// <param name="methodID">The abstract method identifier.</param>
        /// <param name="methodSearchPath">The method search path.</param>
        /// <param name="implementingTypePath">The implementing type path.</param>
        /// <param name="alternativeImplementer">The alternative implementer which can define requested method.</param>
        /// <returns>Identifier of implementing method.</returns>
        /// <inheritdoc />
        public override MethodID GetGenericImplementation(MethodID methodID, PathInfo methodSearchPath, PathInfo implementingTypePath, out PathInfo alternativeImplementer)
        {
            alternativeImplementer = null;
            //get method implemented on type described by dynamicInfo
            var implementingMethod = Naming.ChangeDeclaringType(implementingTypePath.Name, methodID, false);

            var item = getMethodItemFromGeneric(implementingMethod, methodSearchPath);

            if (item == null)
            {
                return(null);
            }

            return(item.Info.MethodID);
        }
Esempio n. 3
0
        /// <summary>
        /// Try to resolve dynamic generic method according to descriptor of called object.
        /// </summary>
        /// <param name="calledObjectDescriptor">Descriptor of called object.</param>
        /// <param name="method">Method that is resolved.</param>
        /// <returns>Resolved method if available, <c>null</c> othewrise.</returns>
        private MethodID tryDynamicGenericResolve(TypeDescriptor calledObjectDescriptor, MethodID method)
        {
            var searchPath = Naming.GetMethodPath(method);

            if (!searchPath.HasGenericArguments)
            {
                //there is no need for generic resolving
                return(null);
            }


            var methodSignature = Naming.ChangeDeclaringType(searchPath.Signature, method, true);
            var typePath        = new PathInfo(calledObjectDescriptor.TypeName);

            var implementersQueue = new Queue <PathInfo>();

            implementersQueue.Enqueue(typePath);
            while (implementersQueue.Count > 0)
            {
                var implementer = implementersQueue.Dequeue();
                foreach (var assembly in _assemblies.Providers)
                {
                    PathInfo alternativeImplementer;
                    var      implementation = assembly.GetGenericImplementation(method, searchPath, implementer, out alternativeImplementer);
                    if (implementation != null)
                    {
                        //implementation has been found
                        return(implementation);
                    }

                    if (alternativeImplementer != null)
                    {
                        implementersQueue.Enqueue(alternativeImplementer);
                    }
                }
            }
            return(null);
        }