I have the following code:
internal class Program
{
private static bool IsMatchingThing1(IThing thing)
{
return thing is
AThing {
Children: [
BThing
]
};
}
private static bool IsMatchingThing2(IThing thing)
{
return thing is
AThing
{
Children:
[
BThing
]
};
}
}
internal interface IThing;
internal class AThing : IThing
{
public List<IThing> Children { get; set; } = new();
}
internal class BThing : IThing
{
public List<IThing> Children { get; set; } = new();
}
The methods IsMatchingThing1 and IsMatchingThing2 contain pattern matching statements, with slightly different formatting, both of which are acceptable to me.
However, if I trigger an automatic reformat (e.g. by retyping the semicolon at the end of the pattern matching statements) Visual Studio reformats this to:
private static bool IsMatchingThing1(IThing thing)
{
return thing is
AThing
{
Children: [
BThing
]
};
}
private static bool IsMatchingThing2(IThing thing)
{
return thing is
AThing
{
Children:
[
BThing
]
};
}
I don't consider this an improvement and would like to retain the formatting used in both, or at least one of the methods. I don't really mind if I am forced to adopt one of the formats.
If I put everything on one line, then the problem doesn't exist, but some of the patterns I need to match are more deeply hierarchical than this example, so some kind of nested indentation is what I'm after.
What settings can I use in .editorconfig that allow some sensible formatting of these statements, and that doesn't cause dotnet format to reformat the code these methods, yet retains the formatting used elsewhere in the code?
dotnet.exe version 9.0.300




dotnet formatreports the formatting as an issue and 'fixes' it as shown above.