diff --git a/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationPropertySymbol.cs b/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationPropertySymbol.cs index 7719be11d3a96..ae188fe3fa67c 100644 --- a/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationPropertySymbol.cs +++ b/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationPropertySymbol.cs @@ -76,7 +76,7 @@ public override TResult Accept(SymbolVisitor this.GetMethod == null && this.SetMethod != null; - public bool IsRequired => Modifiers.IsRequired; + public bool IsRequired => Modifiers.IsRequired && !IsIndexer; public new IPropertySymbol OriginalDefinition => this; diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs index 325ec05e3df62..c69892ee4c25f 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs @@ -409,11 +409,6 @@ public static async Task OverridePropertyAsync( codeFactory.IdentifierName("value"))); } - // The user can add required if they want, but if the property being overridden is required, this one needs to be as well. - modifiers = modifiers.WithIsRequired(overriddenProperty.IsIndexer - ? false - : (modifiers.IsRequired || overriddenProperty.IsRequired)); - // Only generate a getter if the base getter is accessible. IMethodSymbol? accessorGet = null; if (overriddenProperty.GetMethod != null && overriddenProperty.GetMethod.IsAccessibleWithin(containingType)) @@ -473,10 +468,10 @@ public static async Task OverrideAsync( ISymbol symbol, INamedTypeSymbol containingType, Document document, - DeclarationModifiers? declarationModifiers = null, + DeclarationModifiers extraDeclarationModifiers = default, CancellationToken cancellationToken = default) { - var modifiers = declarationModifiers ?? GetOverrideModifiers(symbol); + var modifiers = GetOverrideModifiers(symbol) + extraDeclarationModifiers; if (symbol is IMethodSymbol method) {