Skip to content

Commit 8f385db

Browse files
committed
code suggestion
1 parent 51a9ed2 commit 8f385db

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/Caliburn.Micro.Platform/Platforms/Maui/AttachedCollection.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public BindableObject AssociatedObject
4646
/// <param name="item">The item that was added.</param>
4747
protected virtual void OnItemAdded(BindableObject item)
4848
{
49-
if (associatedObject != null && item is IAttachedObject)
49+
if (associatedObject != null && item is IAttachedObject attached)
5050
{
51-
((IAttachedObject)item).Attach(associatedObject);
51+
attached.Attach(associatedObject);
5252
}
5353
}
5454

@@ -58,10 +58,10 @@ protected virtual void OnItemAdded(BindableObject item)
5858
/// <param name="item">The item that was removed.</param>
5959
protected virtual void OnItemRemoved(BindableObject item)
6060
{
61-
if (item is IAttachedObject &&
62-
((IAttachedObject)item).AssociatedObject != null)
61+
if (item is IAttachedObject attached &&
62+
attached.AssociatedObject != null)
6363
{
64-
((IAttachedObject)item).Detach();
64+
attached.Detach();
6565
}
6666
}
6767

src/Caliburn.Micro.Platform/Platforms/Xamarin.Forms/AttachedCollection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public BindableObject AssociatedObject
4646
/// <param name="item">The item that was added.</param>
4747
protected virtual void OnItemAdded(BindableObject item)
4848
{
49-
if (associatedObject != null && item is IAttachedObject)
49+
if (associatedObject != null && item is IAttachedObject attached)
5050
{
51-
((IAttachedObject)item).Attach(associatedObject);
51+
attached.Attach(associatedObject);
5252
}
5353
}
5454

@@ -58,9 +58,9 @@ protected virtual void OnItemAdded(BindableObject item)
5858
/// <param name="item">The item that was removed.</param>
5959
protected virtual void OnItemRemoved(BindableObject item)
6060
{
61-
if (item is IAttachedObject && ((IAttachedObject)item).AssociatedObject != null)
61+
if (item is IAttachedObject attached && attached.AssociatedObject != null)
6262
{
63-
((IAttachedObject)item).Detach();
63+
attached.Detach();
6464
}
6565
}
6666

0 commit comments

Comments
 (0)