Skip to content

SA1649 broken for generic delegate types #3468

@rdeago

Description

@rdeago

A file containing this code:

namespace MyProgram;

public delegate void Foo<T>(T arg);

should be called "Foo`1.cs" (assuming fileNamingConvention = "metadata" in stylecop.json). Yet SA1649 (File name should match first type name) is triggered unless the file name is "Foo.cs".

Things start going downhill fast if you have multiple Foo<> delegates:

namespace MyProgram;

public delegate void Foo<T>(T arg);

public delegate void Foo<T1,T2>(T1 arg1, T2 arg2);

Now the two delegate types cannot be in two separate files, as they should both be names "Foo.cs". However, keeping them both in "Foo.cs" triggers SA1402 (File may only contain a single type).

The possible workarounds are pretty obvious (either disable SA1402 in "Foo.cs", or disable SA1649 in all "Foo`{n}.cs" files) but this behavior of SA1649 still looks like a bug to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions