Files
ILSpy/ICSharpCode.Decompiler.Generators/RoslynHelpers.cs
T
Siegfried Pammer b75ea27800 Generate DecompilerSettings boilerplate from [DecompilerSetting] attributes
Every version-gated setting was bookkept in four places that had to stay
in sync by hand: the property boilerplate, SetLanguageVersion,
GetMinimumRequiredVersion, and the [Category] display string - and that
sync had already drifted in a handful of settings. A new source
generator in ICSharpCode.Decompiler.Generators now derives all four
from a single [DecompilerSetting] attribute on a partial property:
backing field, accessors with change notification, the version-derived
[Category], and both version methods. [Description] stays handwritten
because its resource keys are irregular and are grepped from the resx.

This commit is a 1:1 translation: the current inconsistencies are
reproduced exactly (AffectsMinimumRequiredVersion = false on
ExtensionMethods, UseLambdaSyntax and UseEnhancedUsing; no gate on
SwitchOnReadOnlySpanChar), verified against the old build by comparing
SetLanguageVersion and GetMinimumRequiredVersion behavior for every
setting at every language version, plus a reflection diff of the full
per-property attribute surface.

Assisted-by: Claude:claude-fable-5:Claude Code
2026-08-09 17:11:41 +02:00

55 lines
2.0 KiB
C#

// Copyright (c) 2026 Siegfried Pammer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using Microsoft.CodeAnalysis;
namespace ICSharpCode.Decompiler.Generators;
public static class RoslynHelpers
{
/// <summary>
/// Post-init source declaring Microsoft.CodeAnalysis.EmbeddedAttribute. Every generator that
/// emits embedded attribute types has to ship its own copy in its own post-init output; the
/// declarations merge only while they stay partial and textually compatible, so all generators
/// must build their copy from this single constant.
/// </summary>
public const string EmbeddedAttributeSource = @"
namespace Microsoft.CodeAnalysis
{
internal sealed partial class EmbeddedAttribute : global::System.Attribute
{
}
}
";
public static bool IsDerivedFrom(this INamedTypeSymbol type, INamedTypeSymbol baseType)
{
INamedTypeSymbol? t = type;
while (t != null)
{
if (SymbolEqualityComparer.Default.Equals(t, baseType))
return true;
t = t.BaseType;
}
return false;
}
}