Skip to content

Commit c0bc073

Browse files
github-actions[bot]PureWeen
authored andcommitted
[create-pull-request] automated change (#30043)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 66fb6da commit c0bc073

File tree

2 files changed

+71
-71
lines changed

2 files changed

+71
-71
lines changed

src/Controls/src/Core/DepdendentHandle.cs

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -15,82 +15,82 @@ namespace System.Runtime;
1515
/// </summary>
1616
internal class DependentHandle : IDisposable
1717
{
18-
private readonly ConditionalWeakTable<object, object> _table;
19-
private readonly WeakReference<object> _primaryRef;
20-
private bool _disposed;
18+
private readonly ConditionalWeakTable<object, object> _table;
19+
private readonly WeakReference<object> _primaryRef;
20+
private bool _disposed;
2121

22-
/// <summary>
23-
/// Initializes a new instance of DependentHandle with a primary and dependent object.
24-
/// </summary>
25-
/// <param name="primary">The primary object that controls the lifetime of the dependent object.</param>
26-
/// <param name="dependent">The dependent object that will be collected when primary is collected.</param>
27-
public DependentHandle(object primary, object? dependent)
28-
{
29-
_table = new ConditionalWeakTable<object, object>();
30-
_primaryRef = new WeakReference<object>(primary);
22+
/// <summary>
23+
/// Initializes a new instance of DependentHandle with a primary and dependent object.
24+
/// </summary>
25+
/// <param name="primary">The primary object that controls the lifetime of the dependent object.</param>
26+
/// <param name="dependent">The dependent object that will be collected when primary is collected.</param>
27+
public DependentHandle(object primary, object? dependent)
28+
{
29+
_table = new ConditionalWeakTable<object, object>();
30+
_primaryRef = new WeakReference<object>(primary);
3131

32-
// Store the dependent object in the table, keyed by the primary object
33-
if (dependent is not null)
34-
{
35-
_table.Add(primary, dependent);
36-
}
37-
}
32+
// Store the dependent object in the table, keyed by the primary object
33+
if (dependent is not null)
34+
{
35+
_table.Add(primary, dependent);
36+
}
37+
}
3838

39-
/// <summary>
40-
/// Gets the primary object if it's still alive, otherwise returns null.
41-
/// </summary>
42-
public object? Target
43-
{
44-
get
45-
{
46-
if (_disposed)
47-
return null;
39+
/// <summary>
40+
/// Gets the primary object if it's still alive, otherwise returns null.
41+
/// </summary>
42+
public object? Target
43+
{
44+
get
45+
{
46+
if (_disposed)
47+
return null;
4848

49-
return _primaryRef.TryGetTarget(out var target) ? target : null;
50-
}
51-
}
49+
return _primaryRef.TryGetTarget(out var target) ? target : null;
50+
}
51+
}
5252

53-
/// <summary>
54-
/// Gets the dependent object if the primary object is still alive, otherwise returns null.
55-
/// </summary>
56-
public object? Dependent
57-
{
58-
get
59-
{
60-
if (_disposed)
61-
return null;
53+
/// <summary>
54+
/// Gets the dependent object if the primary object is still alive, otherwise returns null.
55+
/// </summary>
56+
public object? Dependent
57+
{
58+
get
59+
{
60+
if (_disposed)
61+
return null;
6262

63-
if (_primaryRef.TryGetTarget(out var primary) &&
64-
_table.TryGetValue(primary, out var dependent))
65-
{
66-
return dependent;
67-
}
63+
if (_primaryRef.TryGetTarget(out var primary) &&
64+
_table.TryGetValue(primary, out var dependent))
65+
{
66+
return dependent;
67+
}
6868

69-
return null;
70-
}
71-
}
69+
return null;
70+
}
71+
}
7272

73-
/// <summary>
74-
/// Checks if both primary and dependent objects are still alive.
75-
/// </summary>
76-
public bool IsAllocated => Target is not null && Dependent is not null;
73+
/// <summary>
74+
/// Checks if both primary and dependent objects are still alive.
75+
/// </summary>
76+
public bool IsAllocated => Target is not null && Dependent is not null;
7777

78-
/// <summary>
79-
/// Disposes the DependentHandleCWT, clearing all references.
80-
/// </summary>
81-
public void Dispose()
82-
{
83-
if (_disposed)
84-
return;
78+
/// <summary>
79+
/// Disposes the DependentHandleCWT, clearing all references.
80+
/// </summary>
81+
public void Dispose()
82+
{
83+
if (_disposed)
84+
return;
8585

86-
_disposed = true;
86+
_disposed = true;
8787

88-
// Clear the table - this will allow dependent objects to be collected
89-
// even if the primary object is still alive
90-
if (_primaryRef.TryGetTarget(out var primary))
91-
{
92-
_table.Remove(primary);
93-
}
94-
}
88+
// Clear the table - this will allow dependent objects to be collected
89+
// even if the primary object is still alive
90+
if (_primaryRef.TryGetTarget(out var primary))
91+
{
92+
_table.Remove(primary);
93+
}
94+
}
9595
}
9696
#endif

src/Controls/tests/Core.UnitTests/CommandTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public void ExecuteDoesNotRunIfValueTypeAndSetToNull()
255255
command.Execute(null); // "null is not a valid value for int"
256256
Assert.True(executions == 0, "the command should not have executed");
257257
}
258-
258+
259259
[Theory]
260260
[InlineData(typeof(Button), true)]
261261
[InlineData(typeof(Button), false)]
@@ -294,10 +294,10 @@ public async Task CommandsSubscribedToCanExecuteCollect(Type controlType, bool u
294294
case RefreshView r:
295295
r.Command = command;
296296
break;
297-
case TextCell t:
297+
case TextCell t:
298298
t.Command = command;
299299
break;
300-
case ImageButton i:
300+
case ImageButton i:
301301
i.Command = command;
302302
break;
303303
case MenuItem m:
@@ -321,7 +321,7 @@ public async Task CommandsSubscribedToCanExecuteCollect(Type controlType, bool u
321321
weakReferences.Add(new WeakReference(commandElement.CleanupTracker));
322322
weakReferences.Add(new WeakReference(commandElement.CleanupTracker.Proxy));
323323
}
324-
else if(control is SearchHandler searchHandler)
324+
else if (control is SearchHandler searchHandler)
325325
{
326326
// Add weak references to the command and its cleanup tracker
327327
weakReferences.Add(new WeakReference(searchHandler.CommandSubscription));
@@ -343,7 +343,7 @@ public async Task CommandsSubscribedToCanExecuteCollect(Type controlType, bool u
343343
Assert.True(weakRef.IsAlive);
344344
}
345345
}
346-
346+
347347
foreach (var weakRef in weakReferences)
348348
{
349349
Assert.False(await weakRef.WaitForCollect());

0 commit comments

Comments
 (0)