Skip to content

Commit 9c90cfd

Browse files
committed
Drop DAM on the GetHandlerType return value
1 parent 11ea51a commit 9c90cfd

File tree

8 files changed

+10
-29
lines changed

8 files changed

+10
-29
lines changed

src/Controls/src/Core/CheckBox/CheckBox.Handler.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics.CodeAnalysis;
32

43
namespace Microsoft.Maui.Controls;
54

@@ -11,10 +10,8 @@ partial class CheckBox
1110
return new CheckBoxHandler();
1211
}
1312

14-
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
1513
protected override Type? GetHandlerType()
1614
{
17-
RemapForControlsIfNeeded();
1815
return typeof(CheckBoxHandler);
1916
}
2017

src/Controls/src/Core/Element/Element.Handler.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics.CodeAnalysis;
43

54
namespace Microsoft.Maui.Controls;
65

@@ -17,7 +16,6 @@ partial class Element
1716
/// <summary>
1817
/// Create the type of the Handler for the Element.
1918
/// </summary>
20-
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
2119
protected virtual Type? GetHandlerType()
2220
{
2321
return null;
@@ -30,7 +28,6 @@ protected virtual void RemapForControlsIfNeeded()
3028

3129
IElementHandler? IElement.GetElementHandler(IMauiContext context) => GetHandler(context);
3230

33-
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
3431
Type? IElement.GetElementHandlerType() => GetHandlerType();
3532

3633
private static readonly HashSet<Type> s_remappedTypes = new ();

src/Controls/src/Core/Label/Label.Handler.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics.CodeAnalysis;
32

43
namespace Microsoft.Maui.Controls;
54

@@ -11,10 +10,8 @@ partial class Label
1110
return new LabelHandler();
1211
}
1312

14-
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
1513
protected override Type? GetHandlerType()
1614
{
17-
RemapForControlsIfNeeded();
1815
return typeof(LabelHandler);
1916
}
2017

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
using System;
2-
using System.Diagnostics.CodeAnalysis;
32

43
namespace Microsoft.Maui.Controls;
54

65
partial class Toolbar
76
{
8-
IElementHandler? IElement.GetElementHandler(IMauiContext context)
9-
{
10-
return null;
11-
}
12-
13-
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
14-
Type? IElement.GetElementHandlerType()
15-
{
16-
return null;
17-
}
7+
IElementHandler? IElement.GetElementHandler(IMauiContext context) => null;
8+
Type? IElement.GetElementHandlerType() => null;
189
}

src/Core/src/Core/IElement.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public interface IElement
2323
/// <summary>
2424
/// Gets the Handler Type for the Element.
2525
/// </summary>
26-
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
2726
Type? GetElementHandlerType();
2827
}
2928
}

src/Core/src/Hosting/IMauiHandlersFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public interface IMauiHandlersFactory : IMauiFactory
1111
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
1212
Type? GetHandlerType(Type iview);
1313

14-
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
1514
Type? GetHandlerType(IElement element);
1615

1716
IElementHandler? GetHandler(IElement element, IMauiContext context);

src/Core/src/Hosting/Internal/MauiHandlersFactory.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public MauiHandlersFactory(IMauiHandlersCollection collection)
3131
return view.GetElementHandler(context);
3232
}
3333

34-
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
3534
public Type? GetHandlerType(IElement view)
3635
{
3736
// Try to get the handler type from the service collection first.

src/Core/src/Platform/ElementExtensions.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ public static partial class ElementExtensions
3434
{
3535
static HashSet<Type> handlersWithConstructors = new HashSet<Type>();
3636

37-
static IElementHandler? CreateTypeWithInjection(this IElement view, IMauiContext mauiContext)
37+
static IElementHandler? CreateTypeWithInjection(this Type viewType, IMauiContext mauiContext)
3838
{
39-
var handlerType = mauiContext.Handlers.GetHandlerType(view);
39+
#pragma warning disable CS0618 // Type or member is obsolete
40+
var handlerType = mauiContext.Handlers.GetHandlerType(viewType);
41+
#pragma warning restore CS0618
4042

4143
if (handlerType == null)
4244
return null;
@@ -76,15 +78,15 @@ public static IElementHandler ToHandler(this IElement view, IMauiContext context
7678
try
7779
{
7880
if (handlersWithConstructors.Contains(viewType))
79-
handler = view.CreateTypeWithInjection(context);
80-
else
81+
handler = viewType.CreateTypeWithInjection(context);
82+
else
8183
handler = context.Handlers.GetHandler(view, context);
8284
}
8385
catch (MissingMethodException)
8486
{
85-
handler = view.CreateTypeWithInjection(context);
87+
handler = viewType.CreateTypeWithInjection(context);
8688
if (handler != null)
87-
handlersWithConstructors.Add(view.GetType());
89+
handlersWithConstructors.Add(viewType);
8890
}
8991
}
9092

0 commit comments

Comments
 (0)