public ClassDeclarationSyntax StubMethod(ClassDeclarationSyntax classDclr, IMethodSymbol methodSymbol, INamedTypeSymbol stubbedInterface, SemanticModel semanticModel) { if (!methodSymbol.IsOrdinaryMethod()) { return(classDclr); } MethodDeclarationSyntax methodDclr = SF.MethodDeclaration( SF.ParseTypeName(methodSymbol.ReturnType.GetFullyQualifiedName()), methodSymbol.GetGenericName()); methodDclr = methodDclr.WithParameterList(methodDclr.ParameterList.AddParameters( RoslynUtils.GetMethodParameterSyntaxList(methodSymbol).ToArray())); methodDclr = methodDclr.WithSemicolonToken(SF.Token(SyntaxKind.None)) .WithExplicitInterfaceSpecifier( SF.ExplicitInterfaceSpecifier( SF.IdentifierName(methodSymbol.GetContainingInterfaceGenericQualifiedName()))); string delegateTypeName = NamingUtils.GetDelegateTypeName(methodSymbol, stubbedInterface); string parameters = StubbingUtils.FormatParameters(methodSymbol); var outParameters = methodSymbol.Parameters.Where(p => p.RefKind == RefKind.Out); var methodBlock = StubbingUtils.GetInvocationBlockSyntax(delegateTypeName, methodSymbol.GetGenericName(), parameters, outParameters, methodSymbol.ReturnType, semanticModel); classDclr = classDclr.AddMembers(methodDclr.WithBody(methodBlock)); return(classDclr); }
public ClassDeclarationSyntax StubMethod(ClassDeclarationSyntax classDclr, IMethodSymbol methodSymbol, INamedTypeSymbol stubbedInterface) { if (!methodSymbol.IsOrdinaryMethod()) { return(classDclr); } MethodDeclarationSyntax methodDclr = SF.MethodDeclaration( SF.ParseTypeName(methodSymbol.ReturnType.GetFullyQualifiedName()), methodSymbol.GetGenericName()); methodDclr = methodDclr.WithParameterList(methodDclr.ParameterList.AddParameters( RoslynUtils.GetMethodParameterSyntaxList(methodSymbol).ToArray())); methodDclr = methodDclr.WithSemicolonToken(SF.Token(SyntaxKind.None)) .WithExplicitInterfaceSpecifier( SF.ExplicitInterfaceSpecifier( SF.IdentifierName(methodSymbol.GetContainingInterfaceGenericQualifiedName()))); string delegateTypeName = NamingUtils.GetDelegateTypeName(methodSymbol, stubbedInterface); string parameters = StubbingUtils.FormatParameters(methodSymbol); string callDelegateStmt = StubbingUtils.GenerateInvokeDelegateStmt(delegateTypeName, methodSymbol.GetGenericName(), parameters); if (!methodSymbol.ReturnsVoid) { callDelegateStmt = callDelegateStmt.Insert(0, "return "); } classDclr = classDclr.AddMembers( methodDclr.WithBody(SF.Block(SF.ParseStatement(callDelegateStmt)))); return(classDclr); }
private static DelegateDeclarationSyntax GenerateDelegateDclr(IMethodSymbol methodSymbol, string delegateName, INamedTypeSymbol stubbedInterface) { SyntaxKind visibility = RoslynUtils.GetVisibilityKeyword(stubbedInterface); List <ParameterSyntax> paramsSyntaxList = RoslynUtils.GetMethodParameterSyntaxList(methodSymbol); DelegateDeclarationSyntax delegateDeclaration = SF.DelegateDeclaration(SF.ParseTypeName(methodSymbol.ReturnType.GetFullyQualifiedName()), delegateName) .AddModifiers(SF.Token(visibility)).AddParameterListParameters(paramsSyntaxList.ToArray()); delegateDeclaration = RoslynUtils.CopyGenericConstraints(methodSymbol, delegateDeclaration); return(delegateDeclaration); }
private BasePropertyDeclarationSyntax CreatePropertyDclr(IMethodSymbol methodSymbol, string propType) { if (methodSymbol.IsIndexerAccessor()) { IndexerDeclarationSyntax indexerDclr = SF.IndexerDeclaration( SF.ParseTypeName(propType)) .WithExplicitInterfaceSpecifier(SF.ExplicitInterfaceSpecifier( SF.IdentifierName(methodSymbol.GetContainingInterfaceGenericQualifiedName()))); indexerDclr = indexerDclr.AddParameterListParameters( RoslynUtils.GetMethodParameterSyntaxList(methodSymbol).ToArray()); return(indexerDclr); } string propName = methodSymbol.AssociatedSymbol.Name; PropertyDeclarationSyntax propDclr = SF.PropertyDeclaration(SF.ParseTypeName(propType), SF.Identifier(propName)) .WithExplicitInterfaceSpecifier(SF.ExplicitInterfaceSpecifier( SF.IdentifierName(methodSymbol.GetContainingInterfaceGenericQualifiedName()))); return(propDclr); }
private static ParameterSyntax[] GetEventParameters(IEventSymbol eventSymbol, bool isCustomDelegateEvent) { var parameters = new List <ParameterSyntax>(); INamedTypeSymbol type = (INamedTypeSymbol)(eventSymbol.Type); if (isCustomDelegateEvent) { IMethodSymbol delegateInvokeMethodSymbol = ((INamedTypeSymbol)(eventSymbol.OriginalDefinition).Type).DelegateInvokeMethod; parameters.AddRange(RoslynUtils.GetMethodParameterSyntaxList(delegateInvokeMethodSymbol).ToArray()); } else { parameters.Add(SF.Parameter(SF.Identifier("sender")).WithType(SF.ParseTypeName("object"))); if (type.TypeArguments.Any()) { parameters.Add(SF.Parameter(SF.Identifier("args")) .WithType(SF.ParseTypeName(type.TypeArguments[0].Name))); } } return(parameters.ToArray()); }