Example #1
0
        /// <summary>
        /// Build <see cref="MethodItem" /> from given <see cref="CodeFunction" />.
        /// </summary>
        /// <param name="element">Method definition element.</param>
        /// <returns>Built method.</returns>
        public MethodItem BuildFrom(CodeFunction element)
        {
            var sourceCode = element.MustImplement ? null : GetSourceCode(element);
            var isCtor     = MethodInfo.MethodName == Naming.CtorName;

            if (isCtor)
            {
                //ctor can have precode
                sourceCode = GetPreCode(element) + sourceCode;
            }

            var namespaces = DeclaringAssembly.GetNamespaces(element as CodeElement);

            //get generic parameters info
            var fullname    = element.FullName;
            var genericPath = new PathInfo(fullname);

            var activation = new ParsingActivation(sourceCode, MethodInfo, genericPath.GenericArgs, namespaces);

            RegisterActivation(activation, element as CodeElement);

            var generator = new SourceMethodGenerator(activation, DeclaringAssembly.ParsingProvider);
            var item      = new MethodItem(generator, MethodInfo);

            return(item);
        }
Example #2
0
        /// <inheritdoc />
        public MethodItem Make(PathInfo methodPath, TypeMethodInfo methodDefinition)
        {
            var specializedMethod = Activation.Method.MakeGenericMethod(methodPath);

            var activation = new ParsingActivation(Activation.SourceCode, specializedMethod, Activation.GenericParameters, Activation.Namespaces);

            activation.NavigationRequested  += Activation.OnNavigated;
            activation.SourceChangeCommited += Activation.OnCommited;

            var specializedGenerator = new SourceMethodGenerator(activation, _parsingProvider);

            return(new MethodItem(specializedGenerator, specializedMethod));
        }