Skip to content

extension block is not analyzed for purpose of suppressing CA1859 #7768

@PetSerAl

Description

@PetSerAl
public static class CA1859Test
{
	extension(object)
	{
		public static void Inside() => GetType(M1);
	}

	public static void Outside() => GetType(M2);

	public static Type GetType<T>(Func<T> f) => typeof(T);

	private static object M1() => string.Empty; //CA1859

	private static object M2() => string.Empty;
}

This code produce CA1859 (Change return type of method 'M1' from 'object' to 'string' for improved performance) for M1 where M1 used in extension block, but not for M2, where M2 used outside extension block.

In practical code it is services.AddSingleton(CreateImplementation);, where CreateImplementation return type is used as service type to register in service collection, so it can not be just changed.

SDK version: 10.0.100-rc.2.25502.107

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions