Skip to content

Commit 10fbbe5

Browse files
committed
Fix .NET Framework build errors and MAUI Visibility ambiguity
- Add RequiresUnreferencedCodeAttribute polyfill for net462/net472/net481 targets where the attribute is inaccessible (only public in .NET 5+) - Add ModuleInitializerAttribute polyfill for benchmark net462 target - Fix CS0104 Visibility ambiguity in MAUI project on Windows targets by using type aliases instead of namespace imports
1 parent ecc9e66 commit 10fbbe5

4 files changed

Lines changed: 80 additions & 4 deletions

File tree

src/ReactiveUI.Binding.Maui/BooleanToVisibilityTypeConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// See the LICENSE file in the project root for full license information.
44

55
#if WINUI_TARGET
6-
using Microsoft.UI.Xaml;
6+
using Visibility = Microsoft.UI.Xaml.Visibility;
77
#else
8-
using Microsoft.Maui;
8+
using Visibility = Microsoft.Maui.Visibility;
99
#endif
1010

1111
namespace ReactiveUI.Binding.Maui;

src/ReactiveUI.Binding.Maui/VisibilityToBooleanTypeConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// See the LICENSE file in the project root for full license information.
44

55
#if WINUI_TARGET
6-
using Microsoft.UI.Xaml;
6+
using Visibility = Microsoft.UI.Xaml.Visibility;
77
#else
8-
using Microsoft.Maui;
8+
using Visibility = Microsoft.Maui.Visibility;
99
#endif
1010

1111
namespace ReactiveUI.Binding.Maui;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2019-2026 ReactiveUI Association Incorporated. All rights reserved.
2+
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for full license information.
4+
5+
// Polyfill implementation adapted from SimonCropp/Polyfill
6+
// https://github.com/SimonCropp/Polyfill
7+
#if !NET
8+
9+
namespace System.Diagnostics.CodeAnalysis;
10+
11+
/// <summary>
12+
/// Indicates that the specified method requires dynamic access to code that is not referenced
13+
/// statically, for example through <see cref="System.Reflection"/>.
14+
/// </summary>
15+
/// <remarks>
16+
/// Link: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.requiresunreferencedcodeattribute.
17+
/// </remarks>
18+
[ExcludeFromCodeCoverage]
19+
[DebuggerNonUserCode]
20+
[AttributeUsage(
21+
AttributeTargets.Method |
22+
AttributeTargets.Constructor |
23+
AttributeTargets.Class,
24+
Inherited = false)]
25+
internal sealed class RequiresUnreferencedCodeAttribute : Attribute
26+
{
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="RequiresUnreferencedCodeAttribute"/> class
29+
/// with the specified message.
30+
/// </summary>
31+
/// <param name="message">A message that contains information about the usage of unreferenced code.</param>
32+
public RequiresUnreferencedCodeAttribute(string message) =>
33+
Message = message;
34+
35+
/// <summary>
36+
/// Gets a message that contains information about the usage of unreferenced code.
37+
/// </summary>
38+
public string Message { get; }
39+
40+
/// <summary>
41+
/// Gets or sets an optional URL that contains more information about the method,
42+
/// why it requires unreferenced code, and what options a consumer has to deal with it.
43+
/// </summary>
44+
public string? Url { get; set; }
45+
}
46+
47+
#else
48+
using System.Runtime.CompilerServices;
49+
50+
[assembly: TypeForwardedTo(typeof(System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute))]
51+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2019-2026 ReactiveUI Association Incorporated. All rights reserved.
2+
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for full license information.
4+
5+
// Polyfill implementation adapted from SimonCropp/Polyfill
6+
// https://github.com/SimonCropp/Polyfill
7+
#if !NET5_0_OR_GREATER
8+
9+
namespace System.Runtime.CompilerServices;
10+
11+
/// <summary>
12+
/// Used to indicate to the compiler that a method should be called in its containing
13+
/// module's initializer.
14+
/// </summary>
15+
/// <remarks>
16+
/// When one or more valid methods with this attribute are found in a compilation, the compiler
17+
/// will emit a module initializer that calls each of the attributed methods.
18+
/// On .NET Framework this polyfill enables compilation only; the runtime does not invoke module initializers.
19+
/// </remarks>
20+
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
21+
internal sealed class ModuleInitializerAttribute : Attribute
22+
{
23+
}
24+
25+
#endif

0 commit comments

Comments
 (0)