Example #1
0
            private IList <SyntaxNode> GenerateStatements(
                SyntaxGenerator factory,
                bool isAbstract,
                CancellationToken cancellationToken)
            {
                var throwStatement = CodeGenerationHelpers.GenerateThrowStatement(factory, this.Document, "System.NotImplementedException", cancellationToken);

                return(isAbstract || State.TypeToGenerateIn.TypeKind == TypeKind.Interface || throwStatement == null
                    ? null
                    : new[] { throwStatement });
            }
Example #2
0
            private ImmutableArray <SyntaxNode> GenerateStatements(
                SyntaxGenerator factory,
                bool isAbstract,
                CancellationToken cancellationToken)
            {
                var throwStatement = CodeGenerationHelpers.GenerateThrowStatement(factory, this.Document, "System.NotImplementedException", cancellationToken);

                return(isAbstract || State.TypeToGenerateIn.TypeKind == TypeKind.Interface || throwStatement == null
                    ? default(ImmutableArray <SyntaxNode>)
                    : ImmutableArray.Create(throwStatement));
            }
Example #3
0
            private ImmutableArray <SyntaxNode> GenerateStatements(
                CancellationToken cancellationToken)
            {
                var syntaxFactory = _document.Project.Solution.Workspace.Services.GetLanguageServices(_state.TypeToGenerateIn.Language).GetService <SyntaxGenerator>();

                var throwStatement = CodeGenerationHelpers.GenerateThrowStatement(
                    syntaxFactory, this._document, "System.NotImplementedException", cancellationToken);

                return(_state.TypeToGenerateIn.TypeKind != TypeKind.Interface && _returnsByRef
                    ? ImmutableArray.Create(throwStatement)
                    : default(ImmutableArray <SyntaxNode>));
            }
        private IMethodSymbol GetMethodSymbol(
            SemanticDocument document,
            string eventHandlerMethodName,
            AssignmentExpressionSyntax eventHookupExpression,
            CancellationToken cancellationToken)
        {
            var semanticModel = document.SemanticModel as SemanticModel;
            var symbolInfo    = semanticModel.GetSymbolInfo(eventHookupExpression.Left, cancellationToken);

            var symbol = symbolInfo.Symbol;

            if (symbol == null || symbol.Kind != SymbolKind.Event)
            {
                return(null);
            }

            var typeInference = document.Project.LanguageServices.GetService <ITypeInferenceService>();
            var delegateType  = typeInference.InferDelegateType(semanticModel, eventHookupExpression.Right, cancellationToken);

            if (delegateType == null || delegateType.DelegateInvokeMethod == null)
            {
                return(null);
            }

            var syntaxFactory = document.Project.LanguageServices.GetService <SyntaxGenerator>();

            return(CodeGenerationSymbolFactory.CreateMethodSymbol(
                       attributes: null,
                       accessibility: Accessibility.Private,
                       modifiers: new DeclarationModifiers(isStatic: eventHookupExpression.IsInStaticContext()),
                       returnType: delegateType.DelegateInvokeMethod.ReturnType,
                       returnsByRef: delegateType.DelegateInvokeMethod.ReturnsByRef,
                       explicitInterfaceSymbol: null,
                       name: eventHandlerMethodName,
                       typeParameters: null,
                       parameters: delegateType.DelegateInvokeMethod.Parameters,
                       statements: new List <SyntaxNode>
            {
                CodeGenerationHelpers.GenerateThrowStatement(syntaxFactory, document, "System.NotImplementedException", cancellationToken)
            }));
        }