Skip to content

Remove redundant #if NET directives #118421

@xtqqczze

Description

@xtqqczze

The repository contains redundant #if NET conditional compilation directives. This check is unnecessary when a file is only compiled in a .NET (not NET Standard/Framework) build configuration. In any .NET build the NET symbol will always be defined, making the #if NET block effectively always true and thus redundant.

Example

In HuffmanDecodingException.cs, the following code is wrapped in an unnecessary #if NET directive:

#if NET
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
#endif

However, this file is only compiled in the NetCoreAppCurrent build configuration:

<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-maccatalyst;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)-wasi;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-solaris;$(NetCoreAppCurrent)-haiku;$(NetCoreAppCurrent)-android;$(NetCoreAppCurrent)</TargetFrameworks>

Since that configuration targets .NET 10, the NET symbol is always defined, and the directive can be safely removed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions