diff --git a/src/ReactiveUI.SourceGenerators/Core/Helpers/AttributeDefinitions.cs b/src/ReactiveUI.SourceGenerators/Core/Helpers/AttributeDefinitions.cs index f77fa84..32e29c9 100644 --- a/src/ReactiveUI.SourceGenerators/Core/Helpers/AttributeDefinitions.cs +++ b/src/ReactiveUI.SourceGenerators/Core/Helpers/AttributeDefinitions.cs @@ -259,5 +259,32 @@ namespace ReactiveUI.SourceGenerators.WinForms; internal sealed class RoutedControlHostAttribute(string? baseType) : Attribute; #nullable restore #pragma warning restore +"""; + + public const string IsExternalInitType = "System.Runtime.CompilerServices.IsExternalInit"; + public const string IsExternalInit = """ +// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for full license information. + +// +#pragma warning disable + +#if !NET5_0_OR_GREATER + +namespace System.Runtime.CompilerServices; + +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +/// +/// Reserved to be used by the compiler for tracking metadata. This class should not be used by developers in source code. +/// +[ExcludeFromCodeCoverage] +[DebuggerNonUserCode] +static class IsExternalInit; + +#endif """; } diff --git a/src/ReactiveUI.SourceGenerators/Reactive/ReactiveGenerator.cs b/src/ReactiveUI.SourceGenerators/Reactive/ReactiveGenerator.cs index 252fad9..4b03d83 100644 --- a/src/ReactiveUI.SourceGenerators/Reactive/ReactiveGenerator.cs +++ b/src/ReactiveUI.SourceGenerators/Reactive/ReactiveGenerator.cs @@ -33,6 +33,9 @@ public void Initialize(IncrementalGeneratorInitializationContext context) // Add the ReactiveAttribute to the compilation ctx.AddSource($"{AttributeDefinitions.ReactiveAttributeType}.g.cs", SourceText.From(AttributeDefinitions.ReactiveAttribute, Encoding.UTF8)); + + // Add the IsExternalInit type to the compilation + ctx.AddSource($"{AttributeDefinitions.IsExternalInitType}.g.cs", SourceText.From(AttributeDefinitions.IsExternalInit, Encoding.UTF8)); }); // Gather info for all annotated command methods (starting from method declarations with at least one attribute)