예제 #1
0
 protected virtual MethodDeclarationSyntax ExplicitInterfaceMemberMethodDeclaration(TypeSyntax returnType)
 {
     return(F.MethodDeclaration(returnType, Symbol.Name)
            .WithParameterList(Symbol.Parameters.AsParameterList(TypesForSymbols))
            .WithExplicitInterfaceSpecifier(F.ExplicitInterfaceSpecifier(TypesForSymbols.ParseName(InterfaceSymbol))));
 }
        private MemberDeclarationSyntax ExplicitInterfaceMember()
        {
            var mockedIndexer = F.IndexerDeclaration(ValueWithReadonlyTypeSyntax)
                                .WithParameterList(F.BracketedParameterList(F.SeparatedList(Symbol.Parameters.Select(a =>
                                                                                                                     F.Parameter(F.Identifier(a.Name)).WithType(TypesForSymbols.ParseTypeName(a.Type, a.NullableOrOblivious()))))))
                                .WithExplicitInterfaceSpecifier(F.ExplicitInterfaceSpecifier(TypesForSymbols.ParseName(InterfaceSymbol)));

            if (Symbol.IsReadOnly)
            {
                ExpressionSyntax invocation = F.InvocationExpression(F.IdentifierName(MemberMockName),
                                                                     F.ArgumentList(F.SeparatedList(Symbol.Parameters.Select(a => F.Argument(F.IdentifierName(a.Name))))));
                if (Symbol.ReturnsByRef || Symbol.ReturnsByRefReadonly)
                {
                    invocation = F.RefExpression(invocation);
                }

                mockedIndexer = mockedIndexer
                                .WithExpressionBody(F.ArrowExpressionClause(invocation))
                                .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken));
            }
            else
            {
                if (!Symbol.IsWriteOnly)
                {
                    var argumentList = F.SeparatedList(Symbol.Parameters.Select(a => F.Argument(F.IdentifierName(a.Name))));

                    mockedIndexer = mockedIndexer.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                                                                           .WithExpressionBody(F.ArrowExpressionClause(F.InvocationExpression(F.IdentifierName(MemberMockName))
                                                                                                                       .WithArgumentList(F.ArgumentList(argumentList))))
                                                                           .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken))
                                                                           );
                }

                if (!Symbol.IsReadOnly)
                {
                    var argumentList = F.SeparatedList(Symbol.Parameters.Select(a => F.Argument(F.IdentifierName(a.Name))))
                                       .Add(F.Argument(F.IdentifierName("value")));

                    mockedIndexer = mockedIndexer.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                                                                           .WithExpressionBody(F.ArrowExpressionClause(F.InvocationExpression(F.IdentifierName(MemberMockName),
                                                                                                                                              F.ArgumentList(argumentList))))
                                                                           .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken))
                                                                           );
                }
            }

            return(mockedIndexer);
        }
        private MemberDeclarationSyntax ExplicitInterfaceMember()
        {
            var mockedProperty = F.PropertyDeclaration(ValueWithReadonlyTypeSyntax, Symbol.Name)
                                 .WithExplicitInterfaceSpecifier(F.ExplicitInterfaceSpecifier(TypesForSymbols.ParseName(InterfaceSymbol)));

            if (Symbol.IsReadOnly)
            {
                ExpressionSyntax invocation = F.InvocationExpression(F.IdentifierName(MemberMockName));
                if (Symbol.ReturnsByRef || Symbol.ReturnsByRefReadonly)
                {
                    invocation = F.RefExpression(invocation);
                }

                mockedProperty = mockedProperty
                                 .WithExpressionBody(F.ArrowExpressionClause(invocation))
                                 .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken));
            }
            else
            {
                if (!Symbol.IsWriteOnly)
                {
                    mockedProperty = mockedProperty.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                                                                             .WithExpressionBody(F.ArrowExpressionClause(F.InvocationExpression(F.IdentifierName(MemberMockName))))
                                                                             .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken))
                                                                             );
                }

                if (!Symbol.IsReadOnly)
                {
                    mockedProperty = mockedProperty.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                                                                             .WithExpressionBody(F.ArrowExpressionClause(F.InvocationExpression(F.IdentifierName(MemberMockName),
                                                                                                                                                F.ArgumentList(F.SeparatedList(new[] { F.Argument(F.IdentifierName("value")) })))))
                                                                             .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken))
                                                                             );
                }
            }

            return(mockedProperty);
        }
예제 #4
0
        private MemberDeclarationSyntax ExplicitInterfaceMember()
        {
            var decoratedValueTypeSyntax = ValueTypeSyntax;

            if (Symbol.ReturnsByRef)
            {
                decoratedValueTypeSyntax = F.RefType(decoratedValueTypeSyntax);
            }
            else if (Symbol.ReturnsByRefReadonly)
            {
                decoratedValueTypeSyntax = F.RefType(decoratedValueTypeSyntax).WithReadOnlyKeyword(F.Token(SyntaxKind.ReadOnlyKeyword));
            }

            var mockedProperty = F.PropertyDeclaration(decoratedValueTypeSyntax, Symbol.Name)
                                 .WithExplicitInterfaceSpecifier(F.ExplicitInterfaceSpecifier(TypesForSymbols.ParseName(InterfaceSymbol)));

            if (Symbol.IsReadOnly)
            {
                ExpressionSyntax elementAccess = F.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, F.IdentifierName(MemberMockName),
                                                                          F.IdentifierName("Value"));

                if (Symbol.ReturnsByRef || Symbol.ReturnsByRefReadonly)
                {
                    elementAccess = TypesForSymbols.WrapByRef(elementAccess, ValueTypeSyntax);
                }

                mockedProperty = mockedProperty.WithExpressionBody(F.ArrowExpressionClause(elementAccess))
                                 .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken));
            }
            else
            {
                if (!Symbol.IsWriteOnly)
                {
                    mockedProperty = mockedProperty.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                                                                             .WithExpressionBody(F.ArrowExpressionClause(F.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
                                                                                                                                                  F.IdentifierName(MemberMockName),
                                                                                                                                                  F.IdentifierName("Value"))))
                                                                             .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken))
                                                                             );
                }

                if (!Symbol.IsReadOnly)
                {
                    mockedProperty = mockedProperty.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                                                                             .WithExpressionBody(
                                                                                 F.ArrowExpressionClause(
                                                                                     F.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
                                                                                                            F.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, F.IdentifierName(MemberMockName),
                                                                                                                                     F.IdentifierName("Value")),
                                                                                                            F.IdentifierName("value"))))
                                                                             .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken))
                                                                             );
                }
            }

            return(mockedProperty);
        }
예제 #5
0
        private MemberDeclarationSyntax ExplicitInterfaceMember()
        {
            var decoratedValueTypeSyntax = ValueTypeSyntax;

            if (Symbol.ReturnsByRef)
            {
                decoratedValueTypeSyntax = F.RefType(decoratedValueTypeSyntax);
            }
            else if (Symbol.ReturnsByRefReadonly)
            {
                decoratedValueTypeSyntax = F.RefType(decoratedValueTypeSyntax).WithReadOnlyKeyword(F.Token(SyntaxKind.ReadOnlyKeyword));
            }

            var mockedIndexer = F.IndexerDeclaration(decoratedValueTypeSyntax)
                                .WithParameterList(KeyType.BuildParameterList())
                                .WithExplicitInterfaceSpecifier(F.ExplicitInterfaceSpecifier(TypesForSymbols.ParseName(InterfaceSymbol)));

            var arguments = KeyType.BuildArgumentList();

            if (Symbol.IsReadOnly)
            {
                ExpressionSyntax elementAccess = F.ElementAccessExpression(F.IdentifierName(MemberMockName))
                                                 .WithExpressionsAsArgumentList(arguments);

                if (Symbol.ReturnsByRef || Symbol.ReturnsByRefReadonly)
                {
                    elementAccess = TypesForSymbols.WrapByRef(elementAccess, ValueTypeSyntax);
                }

                mockedIndexer = mockedIndexer.WithExpressionBody(F.ArrowExpressionClause(elementAccess))
                                .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken));
            }
            else
            {
                if (!Symbol.IsWriteOnly)
                {
                    mockedIndexer = mockedIndexer.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                                                                           .WithExpressionBody(F.ArrowExpressionClause(F.ElementAccessExpression(F.IdentifierName(MemberMockName))
                                                                                                                       .WithExpressionsAsArgumentList(arguments)))
                                                                           .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken))
                                                                           );
                }

                if (!Symbol.IsReadOnly)
                {
                    mockedIndexer = mockedIndexer.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                                                                           .WithExpressionBody(F.ArrowExpressionClause(
                                                                                                   F.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression,
                                                                                                                          F.ElementAccessExpression(F.IdentifierName(MemberMockName)).WithExpressionsAsArgumentList(arguments),
                                                                                                                          F.IdentifierName("value"))))
                                                                           .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken)));
                }
            }

            return(mockedIndexer);
        }
        private MemberDeclarationSyntax ExplicitInterfaceMember()
        {
            var parameters = F.SeparatedList(Symbol.Parameters.Select(p => TypesForSymbols.AsParameterSyntax(p)));

            if (ArglistParameterName != null)
            {
                parameters = parameters.Add(F.Parameter(F.Token(SyntaxKind.ArgListKeyword)));
            }

            var arguments = Symbol.Parameters.AsArgumentList();

            if (ArglistParameterName != null && TypesForSymbols.RuntimeArgumentHandle() != null)
            {
                arguments = arguments.Add(F.Argument(F.LiteralExpression(SyntaxKind.ArgListExpression, F.Token(SyntaxKind.ArgListKeyword))));
            }

            var mockedMethod = F.MethodDeclaration(ReturnType, Symbol.Name)
                               .WithParameterList(F.ParameterList(parameters))
                               .WithExplicitInterfaceSpecifier(F.ExplicitInterfaceSpecifier(TypesForSymbols.ParseName(InterfaceSymbol)));

            if (Symbol.TypeParameters.Any())
            {
                mockedMethod = mockedMethod.WithTypeParameterList(TypeParameterList());
            }

            var invocation = Symbol.TypeParameters.Any()
                ? (ExpressionSyntax)F.GenericName(MemberMockName)
                             .WithTypeArgumentList(F.TypeArgumentList(
                                                       F.SeparatedList(Symbol.TypeParameters.Select(typeParameter =>
                                                                                                    TypesForSymbols.ParseTypeName(typeParameter, false)))))
                : F.IdentifierName(MemberMockName);

            invocation = F.InvocationExpression(invocation, F.ArgumentList(arguments));

            if (Symbol.ReturnsByRef || Symbol.ReturnsByRefReadonly)
            {
                invocation = F.RefExpression(invocation);
            }

            mockedMethod = mockedMethod
                           .WithExpressionBody(F.ArrowExpressionClause(invocation))
                           .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken));

            return(mockedMethod);
        }
예제 #7
0
        private MemberDeclarationSyntax ExplicitInterfaceMember()
        {
            var mockedProperty = F.EventDeclaration(EventHandlerTypeSyntax, Symbol.Name)
                                 .WithExplicitInterfaceSpecifier(F.ExplicitInterfaceSpecifier(TypesForSymbols.ParseName(InterfaceSymbol)));

            mockedProperty = mockedProperty.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.AddAccessorDeclaration)
                                                                     .WithExpressionBody(F.ArrowExpressionClause(F.InvocationExpression(
                                                                                                                     F.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, F.IdentifierName(MemberMockName),
                                                                                                                                              F.IdentifierName("Add")))
                                                                                                                 .WithExpressionsAsArgumentList(F.IdentifierName("value"))))
                                                                     .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken))
                                                                     );

            mockedProperty = mockedProperty.AddAccessorListAccessors(F.AccessorDeclaration(SyntaxKind.RemoveAccessorDeclaration)
                                                                     .WithExpressionBody(F.ArrowExpressionClause(F.InvocationExpression(
                                                                                                                     F.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression,
                                                                                                                                              F.IdentifierName(MemberMockName), F.IdentifierName("Remove")))
                                                                                                                 .WithExpressionsAsArgumentList(F.IdentifierName("value"))))
                                                                     .WithSemicolonToken(F.Token(SyntaxKind.SemicolonToken)));

            return(mockedProperty);
        }