All Questions
Tagged with code-formatting c#
118
questions
4
votes
2
answers
190
views
How do you set formatting rules for C# spread operator in Visual Studio?
I know this is probably not the right place to ask this, but I doubt I'd find an answer somewhere else.
Visual Studio 17.9.5 will, by default, format the following snippet as such
int[] arr = [1, 2];
...
0
votes
0
answers
66
views
Ctrl k+D not working on last microsft vs update
After last update of Microsoft VS ctrl K+D for format code not working for razor page although it format cs page
I tried to format form Edit-Advanced-format document but the code didn't format
Then i ...
1
vote
1
answer
158
views
How do I stop ReSharper/Rider from doing this: "}, {"
How do I prevent rider from generating }, { between chopped elements of an initialization?
I looked through Editor --> Code Style --> Braces Layout/Line Breaks and Wrapping, but I may have ...
1
vote
1
answer
135
views
Rider - place curly bracket with offset based on the begining of the parent level, not the parent declaration
I use JetBrains Rider 2022.2.3 Build #RD-222.4167.23, built on September 9, 2022
I want curly braces to be positioned based on the beginning of the level, not the declaration.
For example, I want
var ...
0
votes
2
answers
430
views
Visual Studio Community C# code formatting
I am trying to format C# code of a WinForms .NET Core 7.0 project in Visual Studio Community:
private void Form1_Load(object sender, EventArgs e)
{
Dictionary<String, String> Dictionary = ...
14
votes
1
answer
16k
views
Is there a comprehensive C# linter and formatter like eslint for JS/TS?
I'd like to have my C# projects (.NET Core 3.1+) to be linted and formatted on each build both locally and in CI environment. I know that there's new .NET Analyzers feature and dotnet-format tool in ....
0
votes
1
answer
238
views
Editorconfig indent C# record properties
I am trying to use editorconfig + ReSharper/cleanupcode.exe to format my C# code (using this cool precommit hook)
The problem I am having is that cleanupcode refuses to indent properties in a record
...
0
votes
1
answer
353
views
VS "format document" setting to respect author's newline choices?
Normally my properties look like this ("Version 1"):
public string Foo {get; set;}
I am fine with this. But sometimes my names get long, and it's not so good ("Version 2"):
...
1
vote
1
answer
128
views
ReSharper - format generic type constraint
Here is an example of a generic type constraint declaration from this MSDN page:
class MyClass<T, U>
where T : class
where U : struct
{ }
Is it possible to format my class using ...
5
votes
1
answer
3k
views
Fix Rider C# formatting of linebreaks for method parameter attributes
I prefer having parameter attributes stay on the same line as the parameter itself:
[Authorize]
[HttpPost()]
public async Task<ActionResult<QuoteResponse>> CreateQuoteDataOnly([FromBody] ...
0
votes
2
answers
530
views
How can I determine the names and default values of the formatting options provided by the C#/OmniSharp extension for Visual Studio Code?
I am creating an omnisharp.json file to set my C# formatting preferences. How do I know what properties are available to set and what their default values are?
I can press Ctrl + Space to display ...
1
vote
1
answer
327
views
Automatically Add Self Reference To Properties Of Object
In Visual Studio 2019, when writing .net (C# or VB.net), is there a way to automatically prefix members/ properties of an object with their respective "self" reference?
Eg in c#, automatically ...
1
vote
0
answers
137
views
Line break after opening brace in do-while in Resharper instead of before
I use Resharper a lot and I love it for the most part, but I use Whitesmiths style braces for method bodies and their sub-blocks and I'd like to keep the opening brace on the same line as "do" in do-...
14
votes
1
answer
12k
views
editorconfig - how to specify underscore prefix for readonly private fields? [duplicate]
I haven't been able to find anything on this online.
Is there any way to specify that an underscore prefix for readonly private fields should be added?
Ever since I started using an editorconfig ...
1
vote
1
answer
148
views
Can't compile with 'using' inside the namespace
I have the following code:
using Data;
using MyProject_API.Models.ViewModels;
using System.Linq;
using Utilities.Web.Authentication;
namespace MyProject_API.Services.EmailTemplates
{
/// <...