Skip to content

Commit

Permalink
Put generic constraints on new line
Browse files Browse the repository at this point in the history
closes #527
  • Loading branch information
belav committed Jan 9, 2023
1 parent ccff28f commit 74a3e58
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class ThisIsSomeLongNameAndItShouldFormatWell1
AndYetAnotherLongClassName,
AndStillOneMore { }

public class SimpleGeneric<T> where T : new() { }
public class SimpleGeneric<T>
where T : new() { }

public class LongTypeConstraints<T>
where T : SomeLongNameThatJustKeepsGoing,
Expand All @@ -32,7 +33,8 @@ public class LongerClassNameWithLotsOfGenerics<
TThirdLongName__________________
> : SomeBaseClass<TLongName> { }

public class SimpleGeneric<T> : BaseClass<T> where T : new() { }
public class SimpleGeneric<T> : BaseClass<T>
where T : new() { }

public class ThisIsSomeLongNameAndItShouldFormatWell2<T, T2, T3>
: AnotherLongClassName<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class ThisIsSomeLongNameAndItShouldFormatWell1
AndYetAnotherLongClassName,
AndStillOneMore { }

public class SimpleGeneric<T> where T : new() { }
public class SimpleGeneric<T>
where T : new() { }

public class LongTypeConstraints<T>
where T : SomeLongNameThatJustKeepsGoing,
Expand All @@ -32,7 +33,8 @@ public class LongerClassNameWithLotsOfGenerics<
TThirdLongName__________________
> : SomeBaseClass<TLongName> { }

public class SimpleGeneric<T> : BaseClass<T> where T : new() { }
public class SimpleGeneric<T> : BaseClass<T>
where T : new() { }

public class ThisIsSomeLongNameAndItShouldFormatWell2<T, T2, T3>
: AnotherLongClassName<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ class ClassName
{
delegate void Delegate();

delegate void Delegate<[System.Obsolete()] out T>() where T : struct;
delegate void Delegate<[System.Obsolete()] out T>()
where T : struct;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
delegate void Delegate<T>() where T : struct;
delegate void Delegate<T>()
where T : struct;

class ClassName<T> where T : class
class ClassName<T>
where T : class
{
void MethodName<T>() where T : class
void MethodName<T>()
where T : class
{
void LocalFunction<T>() where T : class
void LocalFunction<T>()
where T : class
{
return;
}
Expand All @@ -31,15 +35,17 @@ class ClassName<T> where T : class
public static ReturnType<T> MethodName<T, U>(
string longParameter_______________________,
string longParameter_______________________
) where T : class
)
where T : class
{
return;
}

public static ReturnType<T> MethodName<T, U>(
string longParameter_______________________,
string longParameter_______________________
) where T : class { }
)
where T : class { }

public static ReturnType<T> MethodName<T, U>(
string longParameter_______________________,
Expand All @@ -59,9 +65,11 @@ class ClassName<T> where T : class
where U : class { }
}

interface InterfaceName<T> where T : class { }
interface InterfaceName<T>
where T : class { }

struct Struct<T> where T : class { }
struct Struct<T>
where T : class { }

class ClassName<N, C, T, TT, L>
where N : new()
Expand Down
3 changes: 1 addition & 2 deletions Src/CSharpier/SyntaxPrinter/ConstraintClauses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ FormattingContext context
{
return Doc.Null;
}
var prefix = constraintClausesList.Count >= 2 ? Doc.HardLine : Doc.Line;
var body = Doc.Join(
Doc.HardLine,
constraintClausesList.Select(o => TypeParameterConstraintClause.Print(o, context))
);

return Doc.Group(Doc.Indent(prefix, body));
return Doc.Group(Doc.Indent(Doc.HardLine, body));
}
}

0 comments on commit 74a3e58

Please sign in to comment.