Esempio n. 1
0
        private static bool IsDuplicateConstraint(TypeParameterConstraintSyntax constraint, SeparatedSyntaxList <TypeParameterConstraintSyntax> constraints)
        {
            int index = constraints.IndexOf(constraint);

            SyntaxKind kind = constraint.Kind();

            switch (kind)
            {
            case SyntaxKind.ClassConstraint:
            case SyntaxKind.StructConstraint:
            {
                for (int i = 0; i < index; i++)
                {
                    if (constraints[i].Kind() == kind)
                    {
                        return(true);
                    }
                }

                break;
            }
            }

            return(false);
        }
Esempio n. 2
0
        private void RemoveConstraint(
            CodeFixContext context,
            Diagnostic diagnostic,
            TypeParameterConstraintSyntax constraint)
        {
            CodeAction codeAction = CodeAction.Create(
                $"Remove constraint '{constraint}'",
                ct => context.Document.RemoveNodeAsync(constraint, ct),
                GetEquivalenceKey(diagnostic, constraint.Kind().ToString()));

            context.RegisterCodeFix(codeAction, diagnostic);
        }
        private static void RemoveConstraint(
            CodeFixContext context,
            Diagnostic diagnostic,
            TypeParameterConstraintSyntax constraint)
        {
            CodeAction codeAction = CodeAction.Create(
                $"Remove constraint '{constraint}'",
                cancellationToken => context.Document.RemoveNodeAsync(constraint, RemoveHelper.GetRemoveOptions(constraint), cancellationToken),
                GetEquivalenceKey(diagnostic, constraint.Kind().ToString()));

            context.RegisterCodeFix(codeAction, diagnostic);
        }
Esempio n. 4
0
        private void RemoveConstraint(
            CodeFixContext context,
            Diagnostic diagnostic,
            TypeParameterConstraintSyntax constraint)
        {
            SeparatedSyntaxList <TypeParameterConstraintSyntax> constraints;

            if (GenericDeclarationHelper.TryGetContainingList(constraint, out constraints))
            {
                CodeAction codeAction = CodeAction.Create(
                    $"Remove constraint '{constraint}'",
                    cancellationToken => context.Document.RemoveNodeAsync(constraint, RemoveHelper.GetRemoveOptions(constraint), cancellationToken),
                    GetEquivalenceKey(diagnostic, constraint.Kind().ToString()));

                context.RegisterCodeFix(codeAction, diagnostic);
            }
        }