Skip to content

Question: Single statement if formatting #13970

@jacobcarpenter

Description

@jacobcarpenter

Looking at System.Threading.Tasks.Dataflow (amazing library by the way), I see three different variations of formatting of single-statement if statements. In one method.

From DataflowBlock.OutputAvailableAsync

One line:

if (source == null) throw new ArgumentNullException("source");

Two lines:

if (cancellationToken.IsCancellationRequested)
    return Common.CreateTaskFromCancellation<bool>(cancellationToken);

With braces:

if (target.Task.IsCompleted)
{
    return target.Task;
}

Are the guidelines for formatting these more nuanced than I'm able to see, or is this just inconsistent formatting? Is this kind of inconsistent formatting normal and acceptable? Is there a preference for how new code should be formatted?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions