Skip to main content

Ignoring Code

Csharpier will ignore the following files

  • Any file that begins with TemporaryGeneratedFile_
  • Any file that ends with .designer.cs
  • Any file that ends with .generated.cs
  • Any file that ends with .g.cs
  • Any file that ends with .g.i.cs
  • Any file that begins with a comment that contains <autogenerated or <auto-generated

Add a .csharpierignore file to ignore additional files and folders. The file uses gitignore syntax

Example

Uploads/
**/App_Data/*.cs

Add a // csharpier-ignore comment to exclude the next node from formatting. This is valid on statements and members.


// csharpier-ignore
public class Unformatted {
private string unformatted;
}

public class ClassName
{
// csharpier-ignore
private string unformatted;

// csharpier-ignore
public void MethodName( ) {
var unformatted = "";
}

public void MethodName()
{
// csharpier-ignore
var unformatted = true;

if (true)
{
// csharpier-ignore
var unformatted = true;
}
}
}

Use a ranged ignore to exclude multiple lines from formatting. A range is valid around statements and members.

// csharpier-ignore-start
public class Unformatted1 { }
public class Unformatted2 { }
// csharpier-ignore-end

public class ClassName
{
// csharpier-ignore-start
private string unformatted1;
private string unformatted2;
public void MethodName( ) {
var unformatted = "";
}
// csharpier-ignore-end
public void MethodName()
{
// csharpier-ignore-start
var unformatted1 = true;
var unformatted2 = true;
if (false) {
return;
}
// csharpier-ignore-end
if (true)
{
// csharpier-ignore-start
var unformatted3 = true;
var unformatted4 = true;
// csharpier-ignore-end

var formatted = true;
}
}
}