Max
Max

Reputation: 23

Nuget-Package or other way to format C# file

Problem

In the last couple of weeks I am creating a application where it is possible to generate a C# class file (.cs file extention). I am trying to find a Nuget-Package, or some other way to format this document so it is readable but I can't seem to find any solution, either no question on here.

I know there is a way to format a document, but this is too much work for my project.

Question

Do any of you have the same "problem" and is there a way to format a document properly?

Some extra explanation

How I want to have my document (kind of) formatted:

GINLoop1 = new List < GINLoop1 > () {
    new GINLoop1 {
        GIN = new GIN {
            Objectidentificationcodequalifier_01 = "test1",
            IDENTITYNUMBERRANGE_02 = new C208_2 {
                Objectidentifier_01 = "test",
                Objectidentifier_02 = null,
            },
            IDENTITYNUMBERRANGE_03 = null,
            IDENTITYNUMBERRANGE_04 = null,
            IDENTITYNUMBERRANGE_05 = null,
            IDENTITYNUMBERRANGE_06 = null,
        },
    },
},

How my document is now formatted:

GINLoop1 = new List < GINLoop1 > () {
new GINLoop1 {
GIN = new GIN {
Objectidentificationcodequalifier_01 = "test1",
IDENTITYNUMBERRANGE_02 = new C208_2 {
Objectidentifier_01 = "test",
Objectidentifier_02 = null,
},
IDENTITYNUMBERRANGE_03 = null,
IDENTITYNUMBERRANGE_04 = null,
IDENTITYNUMBERRANGE_05 = null,
IDENTITYNUMBERRANGE_06 = null,
},
},
},

Upvotes: 0

Views: 900

Answers (2)

Dag Baardsen
Dag Baardsen

Reputation: 922

It's pretty old, but NArrange used to work the way you want. However, I haven't been using it for several years. Check it out on nuget.org here:

https://www.nuget.org/packages/NArrange/

Upvotes: 0

ManIkWeet
ManIkWeet

Reputation: 1338

JetBrains has (free) commandline tools available as a NuGet package, you can find them at https://www.nuget.org/packages/JetBrains.ReSharper.CommandLineTools.

It's not very thoroughly documented but I am sure there's some way to format a .cs file in it. They have code cleanup available in their ReSharper plugin and their Rider IDE, which I believe both make use of this library one way or another.

Upvotes: 1

Related Questions