/// <summary>
        /// Initializes a new instance of the <see cref="MethodASTWalker"/> class.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="methodDeclaration"></param>
        /// <param name="semanticModel">The semantic model.</param>
        protected AnonymousMethodASTWalker(CSharpSyntaxNode node, LambdaTranslationUnit methodDeclaration, SemanticModel semanticModel)
            : base(node, semanticModel)
        {
            var methodDeclarationSyntaxNode = node as AnonymousMethodExpressionSyntax;

            if (methodDeclarationSyntaxNode == null)
            {
                throw new ArgumentException(
                          string.Format("Specified node is not of type {0}",
                                        typeof(AnonymousMethodExpressionSyntax).Name));
            }

            if (methodDeclaration == null)
            {
                throw new ArgumentNullException(nameof(methodDeclaration));
            }

            this.methodDeclaration = methodDeclaration;
        }
示例#2
0
        /// <summary>
        /// Creates a <see cref="MethodDeclarationTranslationUnit"/>.
        /// </summary>
        /// <returns>A <see cref="MethodDeclarationTranslationUnit"/>.</returns>
        public ITranslationUnit Create()
        {
            if (this.DoNotCreateTranslationUnit)
            {
                return(null);
            }

            AnonymousMethodDeclaration helper = new AnonymousMethodDeclaration(this.Node as AnonymousMethodExpressionSyntax, this.SemanticModel);

            var lambdaDeclaration = LambdaTranslationUnit.Create(null);

            //var lambdaDeclaration = LambdaTranslationUnit.Create(TypeIdentifierTranslationUnit.Create(helper.ReturnType.FullName.MapType()));

            foreach (Parameter parameter in helper.Parameters)
            {
                lambdaDeclaration.AddArgument(ArgumentDefinitionTranslationUnit.Create(
                                                  TypeIdentifierTranslationUnit.Create(parameter.Type.TypeSyntaxNode.MapType()),
                                                  IdentifierTranslationUnit.Create(parameter.IdentifierName)));
            }

            return(lambdaDeclaration);
        }
示例#3
0
 /// <summary>
 /// Creates the translation unit.
 /// </summary>
 /// <remarks>
 /// Must return a type inheriting from <see cref="MethodSignatureDeclarationTranslationUnit"/>.
 /// </remarks>
 /// <param name="visibility"></param>
 /// <param name="returnType"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 protected virtual ITranslationUnit CreateTranslationUnit(
     VisibilityToken visibility, ITranslationUnit returnType, ITranslationUnit name)
 {
     return(LambdaTranslationUnit.Create(returnType));
 }
 /// <summary>
 /// Copy initializes a new instance of the <see cref="MethodASTWalker"/> class.
 /// </summary>
 /// <param name="other"></param>
 /// <remarks>
 /// For testability.
 /// </remarks>
 public AnonymousMethodASTWalker(AnonymousMethodASTWalker other)
     : base(other)
 {
     this.methodDeclaration = other.methodDeclaration;
 }