Browse Source

Merge pull request #11192 from AvaloniaUI/add-message-arg-to-the-unstable-attr

Add message to the Unstable attribute
pull/11194/head
Nikita Tsukanov 3 years ago
committed by GitHub
parent
commit
0495f10174
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      nukebuild/RefAssemblyGenerator.cs
  2. 3
      src/Avalonia.Base/Controls/IThemeVariantProvider.cs
  3. 3
      src/Avalonia.Base/Input/DragEventArgs.cs
  4. 3
      src/Avalonia.Base/Input/PointerDeltaEventArgs.cs
  5. 12
      src/Avalonia.Base/Input/PointerEventArgs.cs
  6. 3
      src/Avalonia.Base/Input/PointerWheelEventArgs.cs
  7. 22
      src/Avalonia.Base/Metadata/UnstableAttribute.cs
  8. 2
      src/Avalonia.Base/Platform/IAssetLoader.cs

24
nukebuild/RefAssemblyGenerator.cs

@ -96,7 +96,7 @@ public class RefAssemblyGenerator
| MethodAttributes.HideBySig, type.Module.TypeSystem.Void)); | MethodAttributes.HideBySig, type.Module.TypeSystem.Void));
} }
var forceUnstable = type.CustomAttributes.Any(a => var forceUnstable = type.CustomAttributes.FirstOrDefault(a =>
a.AttributeType.FullName == "Avalonia.Metadata.UnstableAttribute"); a.AttributeType.FullName == "Avalonia.Metadata.UnstableAttribute");
foreach (var m in type.Methods) foreach (var m in type.Methods)
@ -109,22 +109,28 @@ public class RefAssemblyGenerator
} }
} }
static void MarkAsUnstable(IMemberDefinition def, MethodReference obsoleteCtor, bool force) static void MarkAsUnstable(IMemberDefinition def, MethodReference obsoleteCtor, ICustomAttribute unstableAttribute)
{ {
if (!force && ( if (def.CustomAttributes.Any(a => a.AttributeType.FullName == "System.ObsoleteAttribute"))
def.HasCustomAttributes == false
|| def.CustomAttributes.All(a => a.AttributeType.FullName != "Avalonia.Metadata.UnstableAttribute")))
return; return;
if (def.CustomAttributes.Any(a => a.AttributeType.FullName == "System.ObsoleteAttribute")) unstableAttribute = def.CustomAttributes.FirstOrDefault(a =>
a.AttributeType.FullName == "Avalonia.Metadata.UnstableAttribute") ?? unstableAttribute;
if (unstableAttribute is null)
return; return;
var message = unstableAttribute.ConstructorArguments.FirstOrDefault().Value?.ToString();
if (string.IsNullOrEmpty(message))
{
message = "This is a part of unstable API and can be changed in minor releases. Consider replacing it with alternatives or reach out developers on GitHub.";
}
def.CustomAttributes.Add(new CustomAttribute(obsoleteCtor) def.CustomAttributes.Add(new CustomAttribute(obsoleteCtor)
{ {
ConstructorArguments = ConstructorArguments =
{ {
new CustomAttributeArgument(obsoleteCtor.Module.TypeSystem.String, new CustomAttributeArgument(obsoleteCtor.Module.TypeSystem.String, message)
"This is a part of unstable API and can be changed in minor releases. You have been warned")
} }
}); });
} }
@ -168,4 +174,4 @@ public class RefAssemblyGenerator
} }
} }
} }
} }

3
src/Avalonia.Base/Controls/IThemeVariantProvider.cs

@ -10,9 +10,8 @@ namespace Avalonia.Controls;
/// <remarks> /// <remarks>
/// This is a helper interface for the XAML compiler to make Key property accessibly by the markup extensions. /// This is a helper interface for the XAML compiler to make Key property accessibly by the markup extensions.
/// Which means, it can only be used with ResourceDictionaries and markup extensions in the XAML code. /// Which means, it can only be used with ResourceDictionaries and markup extensions in the XAML code.
/// This API might be removed in the future minor updates.
/// </remarks> /// </remarks>
[Unstable] [Unstable("This XAML-only API might be removed in the future minor updates.")]
public interface IThemeVariantProvider : IResourceProvider public interface IThemeVariantProvider : IResourceProvider
{ {
/// <summary> /// <summary>

3
src/Avalonia.Base/Input/DragEventArgs.cs

@ -25,8 +25,7 @@ namespace Avalonia.Input
return _target.TranslatePoint(_targetLocation, relativeTo) ?? new Point(0, 0); return _target.TranslatePoint(_targetLocation, relativeTo) ?? new Point(0, 0);
} }
[Unstable] [Unstable("This constructor might be removed in 12.0. For unit testing, consider using DragDrop.DoDragDrop or IHeadlessWindow.DragDrop.")]
[Obsolete("This constructor might be removed in 12.0. For unit testing, consider using DragDrop.DoDragDrop or IHeadlessWindow.DragDrop.")]
public DragEventArgs(RoutedEvent<DragEventArgs> routedEvent, IDataObject data, Interactive target, Point targetLocation, KeyModifiers keyModifiers) public DragEventArgs(RoutedEvent<DragEventArgs> routedEvent, IDataObject data, Interactive target, Point targetLocation, KeyModifiers keyModifiers)
: base(routedEvent) : base(routedEvent)
{ {

3
src/Avalonia.Base/Input/PointerDeltaEventArgs.cs

@ -9,8 +9,7 @@ namespace Avalonia.Input
{ {
public Vector Delta { get; } public Vector Delta { get; }
[Unstable] [Unstable("This constructor might be removed in 12.0.")]
[Obsolete("This constructor might be removed in 12.0.")]
public PointerDeltaEventArgs(RoutedEvent routedEvent, object? source, public PointerDeltaEventArgs(RoutedEvent routedEvent, object? source,
IPointer pointer, Visual rootVisual, Point rootVisualPosition, ulong timestamp, IPointer pointer, Visual rootVisual, Point rootVisualPosition, ulong timestamp,
PointerPointProperties properties, KeyModifiers modifiers, Vector delta) PointerPointProperties properties, KeyModifiers modifiers, Vector delta)

12
src/Avalonia.Base/Input/PointerEventArgs.cs

@ -14,8 +14,7 @@ namespace Avalonia.Input
private readonly PointerPointProperties _properties; private readonly PointerPointProperties _properties;
private readonly Lazy<IReadOnlyList<RawPointerPoint>?>? _previousPoints; private readonly Lazy<IReadOnlyList<RawPointerPoint>?>? _previousPoints;
[Unstable] [Unstable("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")]
[Obsolete("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")]
public PointerEventArgs(RoutedEvent routedEvent, public PointerEventArgs(RoutedEvent routedEvent,
object? source, object? source,
IPointer pointer, IPointer pointer,
@ -129,8 +128,7 @@ namespace Avalonia.Input
public class PointerPressedEventArgs : PointerEventArgs public class PointerPressedEventArgs : PointerEventArgs
{ {
[Unstable] [Unstable("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")]
[Obsolete("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")]
public PointerPressedEventArgs( public PointerPressedEventArgs(
object source, object source,
IPointer pointer, IPointer pointer,
@ -150,8 +148,7 @@ namespace Avalonia.Input
public class PointerReleasedEventArgs : PointerEventArgs public class PointerReleasedEventArgs : PointerEventArgs
{ {
[Unstable] [Unstable("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")]
[Obsolete("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")]
public PointerReleasedEventArgs( public PointerReleasedEventArgs(
object source, IPointer pointer, object source, IPointer pointer,
Visual rootVisual, Point rootVisualPosition, ulong timestamp, Visual rootVisual, Point rootVisualPosition, ulong timestamp,
@ -173,8 +170,7 @@ namespace Avalonia.Input
{ {
public IPointer Pointer { get; } public IPointer Pointer { get; }
[Unstable] [Unstable("This constructor might be removed in 12.0. If you need to remove capture, use stable methods on the IPointer instance.,")]
[Obsolete("This constructor might be removed in 12.0. If you need to remove capture, use stable methods on the IPointer instance.,")]
public PointerCaptureLostEventArgs(object source, IPointer pointer) : base(InputElement.PointerCaptureLostEvent) public PointerCaptureLostEventArgs(object source, IPointer pointer) : base(InputElement.PointerCaptureLostEvent)
{ {
Pointer = pointer; Pointer = pointer;

3
src/Avalonia.Base/Input/PointerWheelEventArgs.cs

@ -9,8 +9,7 @@ namespace Avalonia.Input
{ {
public Vector Delta { get; } public Vector Delta { get; }
[Unstable] [Unstable("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow.MouseWheel.")]
[Obsolete("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow.MouseWheel.")]
public PointerWheelEventArgs(object source, IPointer pointer, Visual rootVisual, public PointerWheelEventArgs(object source, IPointer pointer, Visual rootVisual,
Point rootVisualPosition, ulong timestamp, Point rootVisualPosition, ulong timestamp,
PointerPointProperties properties, KeyModifiers modifiers, Vector delta) PointerPointProperties properties, KeyModifiers modifiers, Vector delta)

22
src/Avalonia.Base/Metadata/UnstableAttribute.cs

@ -1,4 +1,4 @@
using System; using System;
namespace Avalonia.Metadata namespace Avalonia.Metadata
{ {
@ -9,5 +9,25 @@ namespace Avalonia.Metadata
[AttributeUsage(AttributeTargets.All)] [AttributeUsage(AttributeTargets.All)]
public sealed class UnstableAttribute : Attribute public sealed class UnstableAttribute : Attribute
{ {
/// <summary>
/// Initializes a new instance of the <see cref="UnstableAttribute"/> class.
/// </summary>
public UnstableAttribute()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="UnstableAttribute"/> class.
/// </summary>
/// <param name="message">The text string that describes alternative workarounds.</param>
public UnstableAttribute(string? message)
{
Message = message;
}
/// <summary>
/// Gets a value that indicates whether the compiler will treat usage of the obsolete program element as an error.
/// </summary>
public string? Message { get; }
} }
} }

2
src/Avalonia.Base/Platform/IAssetLoader.cs

@ -9,7 +9,7 @@ namespace Avalonia.Platform
/// <summary> /// <summary>
/// Loads assets compiled into the application binary. /// Loads assets compiled into the application binary.
/// </summary> /// </summary>
[Unstable] [Unstable("IAssetLoader interface and AvaloniaLocator usage is considered unstable. Please use AssetLoader static class instead.")]
public interface IAssetLoader public interface IAssetLoader
{ {
/// <summary> /// <summary>

Loading…
Cancel
Save