Menu

#103 Suggestions for better C# formatting support

None
open
nobody
None
2018-01-29
2017-03-15
NightElf
No

Hi everyone,

First thanks for a great C# formatter with with nice VS support! I have been using it for a whole and found some C# speficic cases where the formatting can be improved. I hope you do not mind my suggestions.


1) In C# it is comon to use properties with get and set block. By default, the formatter puts the set block right behind closing brace ofget. It would be great to have option like --break-closing-breackets-properties because we do not want to enable --break-closing-breackets for the whole project as we like else to be on the same line as closing brace of if for example.

Current behavior:

public int Property {
    get {
        // some code
    } set {
        // some code
    }
}

Desired behavior:

public int Property {
    get {
        // some code
    }
    set {
        // some code
    }
}

2) Formatting of structs with the where keyword double-indents the shole body:

public struct SomeClass<T> : IEquatable<T> where T : class {
        // All code 
        // in the class 
        // is double-indented
}

I would expect just normal indentation:

public struct SomeClass<T> : IEquatable<T> where T : class {
    // some code
    // some code
    // some code
}

Also, when where is broken to next line, there is no indentation:

public int SomeLongMethodSignature<TResult>(int with, int many, int parameters)
where TResult : class {
    // some code
    // some code
    // some code
}

But this is what I would expect:

public int SomeLongMethodSignature<TResult>(int with, int many, int parameters)
        where TResult : class {
    // some code
    // some code
    // some code
}

Or even:

public int SomeLongMethodSignature<TResult>(int with, int many, int parameters)
                        where TResult : class {
    // some code
    // some code
    // some code
}

3) Short syntax for properties is not properly aligned:

public class SomeClass {
    public float SomeProperty
    => 3.14158f;  // Some long property code here.
}

I would expect at least an indent:

public class SomeClass {
    public float SomeProperty
        => 3.14158f;  // Some long property code here.
}

There is more things that I have found so let me know if you are interested in more suggestions.

Thanks!

Discussion

  • Jim Pattee

    Jim Pattee - 2017-03-19

    1) Fixed. This occurred when certain brace styles were used.
    2) Fixed structs with the where keyword .

    These were actually errors in formatting.
    I would like to see what else you have.
    I may not have time to fix everything though.

     
  • NightElf

    NightElf - 2017-03-19

    Thanks a lot for the fixes Jim!

    Any opinion about thewhere alignment and the number 3? Or is current formatting intended?

     
  • Jim Pattee

    Jim Pattee - 2017-03-20

    These wil have to wait for a future release.
    I need to do a new release fairly soon.

     
  • Jim Pattee

    Jim Pattee - 2018-01-29

    Ticket moved from /p/astyle/bugs/430/

     

Log in to post a comment.