Skip to content

Commit cbafa5a

Browse files
authored
Fix Out-GridView by replacing use of obsolete BinaryFormatter with custom implementation (#25497)
1 parent eb1cc6d commit cbafa5a

27 files changed

+346
-48
lines changed

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/ComparableValueFilterRule.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ namespace Microsoft.Management.UI.Internal
1616
[Serializable]
1717
public abstract class ComparableValueFilterRule<T> : FilterRule where T : IComparable
1818
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="ComparableValueFilterRule{T}"/> class.
21+
/// </summary>
22+
protected ComparableValueFilterRule()
23+
{
24+
}
25+
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="ComparableValueFilterRule{T}"/> class.
28+
/// </summary>
29+
/// <param name="source">The source to initialize from.</param>
30+
protected ComparableValueFilterRule(ComparableValueFilterRule<T> source)
31+
: base(source)
32+
{
33+
this.DefaultNullValueEvaluation = source.DefaultNullValueEvaluation;
34+
}
35+
1936
#region Properties
2037

2138
/// <summary>

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/DoesNotEqualFilterRule.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,23 @@ namespace Microsoft.Management.UI.Internal
1717
public class DoesNotEqualFilterRule<T> : EqualsFilterRule<T> where T : IComparable
1818
{
1919
/// <summary>
20-
/// Initializes a new instance of the DoesNotEqualFilterRule class.
20+
/// Initializes a new instance of the <see cref="DoesNotEqualFilterRule{T}"/> class.
2121
/// </summary>
2222
public DoesNotEqualFilterRule()
2323
{
2424
this.DisplayName = UICultureResources.FilterRule_DoesNotEqual;
2525
this.DefaultNullValueEvaluation = true;
2626
}
2727

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="DoesNotEqualFilterRule{T}"/> class.
30+
/// </summary>
31+
/// <param name="source">The source to initialize from.</param>
32+
public DoesNotEqualFilterRule(DoesNotEqualFilterRule<T> source)
33+
: base(source)
34+
{
35+
}
36+
2837
/// <summary>
2938
/// Determines if item is not equal to Value.
3039
/// </summary>

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/EqualsFilterRule.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ namespace Microsoft.Management.UI.Internal
1818
public class EqualsFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
1919
{
2020
/// <summary>
21-
/// Initializes a new instance of the EqualsFilterRule class.
21+
/// Initializes a new instance of the <see cref="EqualsFilterRule{T}"/> class.
2222
/// </summary>
2323
public EqualsFilterRule()
2424
{
2525
this.DisplayName = UICultureResources.FilterRule_Equals;
2626
}
2727

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="EqualsFilterRule{T}"/> class.
30+
/// </summary>
31+
/// <param name="source">The source to initialize from.</param>
32+
public EqualsFilterRule(EqualsFilterRule<T> source)
33+
: base(source)
34+
{
35+
}
36+
2837
/// <summary>
2938
/// Determines if item is equal to Value.
3039
/// </summary>

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/FilterRule.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.Management.UI.Internal
1010
/// </summary>
1111
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
1212
[Serializable]
13-
public abstract class FilterRule : IEvaluate
13+
public abstract class FilterRule : IEvaluate, IDeepCloneable
1414
{
1515
/// <summary>
1616
/// Gets a value indicating whether the FilterRule can be
@@ -34,12 +34,28 @@ public string DisplayName
3434
}
3535

3636
/// <summary>
37-
/// Initializes a new instance of the FilterRule class.
37+
/// Initializes a new instance of the <see cref="FilterRule"/> class.
3838
/// </summary>
3939
protected FilterRule()
4040
{
4141
}
4242

43+
/// <summary>
44+
/// Initializes a new instance of the <see cref="FilterRule"/> class.
45+
/// </summary>
46+
/// <param name="source">The source to initialize from.</param>
47+
protected FilterRule(FilterRule source)
48+
{
49+
ArgumentNullException.ThrowIfNull(source);
50+
this.DisplayName = source.DisplayName;
51+
}
52+
53+
/// <inheritdoc cref="IDeepCloneable.DeepClone()" />
54+
public object DeepClone()
55+
{
56+
return Activator.CreateInstance(this.GetType(), new object[] { this });
57+
}
58+
4359
/// <summary>
4460
/// Gets a value indicating whether the supplied item meets the
4561
/// criteria specified by this rule.

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/FilterRuleExtensions.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Diagnostics;
6-
using System.IO;
7-
using System.Runtime.Serialization;
8-
using System.Runtime.Serialization.Formatters.Binary;
95

106
namespace Microsoft.Management.UI.Internal
117
{
@@ -28,29 +24,7 @@ public static class FilterRuleExtensions
2824
public static FilterRule DeepCopy(this FilterRule rule)
2925
{
3026
ArgumentNullException.ThrowIfNull(rule);
31-
32-
#pragma warning disable SYSLIB0050
33-
Debug.Assert(rule.GetType().IsSerializable, "rule is serializable");
34-
#pragma warning disable SYSLIB0011
35-
BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone));
36-
#pragma warning restore SYSLIB0011
37-
MemoryStream ms = new MemoryStream();
38-
39-
FilterRule copy = null;
40-
try
41-
{
42-
formatter.Serialize(ms, rule);
43-
44-
ms.Position = 0;
45-
copy = (FilterRule)formatter.Deserialize(ms);
46-
#pragma warning restore SYSLIB0050
47-
}
48-
finally
49-
{
50-
ms.Close();
51-
}
52-
53-
return copy;
27+
return (FilterRule)rule.DeepClone();
5428
}
5529
}
5630
}

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/IsBetweenFilterRule.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public ValidatingValue<T> EndValue
5656
#region Ctor
5757

5858
/// <summary>
59-
/// Initializes a new instance of the IsBetweenFilterRule class.
59+
/// Initializes a new instance of the <see cref="IsBetweenFilterRule{T}"/> class.
6060
/// </summary>
6161
public IsBetweenFilterRule()
6262
{
@@ -69,6 +69,20 @@ public IsBetweenFilterRule()
6969
this.EndValue.PropertyChanged += this.Value_PropertyChanged;
7070
}
7171

72+
/// <summary>
73+
/// Initializes a new instance of the <see cref="IsBetweenFilterRule{T}"/> class.
74+
/// </summary>
75+
/// <param name="source">The source to initialize from.</param>
76+
public IsBetweenFilterRule(IsBetweenFilterRule<T> source)
77+
: base(source)
78+
{
79+
this.StartValue = (ValidatingValue<T>)source.StartValue.DeepClone();
80+
this.StartValue.PropertyChanged += this.Value_PropertyChanged;
81+
82+
this.EndValue = (ValidatingValue<T>)source.EndValue.DeepClone();
83+
this.EndValue.PropertyChanged += this.Value_PropertyChanged;
84+
}
85+
7286
#endregion Ctor
7387

7488
#region Public Methods

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/IsEmptyFilterRule.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@ namespace Microsoft.Management.UI.Internal
1414
public class IsEmptyFilterRule : FilterRule
1515
{
1616
/// <summary>
17-
/// Initializes a new instance of the IsEmptyFilterRule class.
17+
/// Initializes a new instance of the <see cref="IsEmptyFilterRule"/> class.
1818
/// </summary>
1919
public IsEmptyFilterRule()
2020
{
2121
this.DisplayName = UICultureResources.FilterRule_IsEmpty;
2222
}
2323

24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="IsEmptyFilterRule"/> class.
26+
/// </summary>
27+
/// <param name="source">The source to initialize from.</param>
28+
public IsEmptyFilterRule(IsEmptyFilterRule source)
29+
: base(source)
30+
{
31+
}
32+
2433
/// <summary>
2534
/// Gets a values indicating whether the supplied item is empty.
2635
/// </summary>

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/IsGreaterThanFilterRule.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ namespace Microsoft.Management.UI.Internal
1818
public class IsGreaterThanFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
1919
{
2020
/// <summary>
21-
/// Initializes a new instance of the IsGreaterThanFilterRule class.
21+
/// Initializes a new instance of the <see cref="IsGreaterThanFilterRule{T}"/> class.
2222
/// </summary>
2323
public IsGreaterThanFilterRule()
2424
{
2525
this.DisplayName = UICultureResources.FilterRule_GreaterThanOrEqual;
2626
}
2727

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="IsGreaterThanFilterRule{T}"/> class.
30+
/// </summary>
31+
/// <param name="source">The source to initialize from.</param>
32+
public IsGreaterThanFilterRule(IsGreaterThanFilterRule<T> source)
33+
: base(source)
34+
{
35+
}
36+
2837
/// <summary>
2938
/// Determines if item is greater than Value.
3039
/// </summary>

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/IsLessThanFilterRule.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ namespace Microsoft.Management.UI.Internal
1818
public class IsLessThanFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
1919
{
2020
/// <summary>
21-
/// Initializes a new instance of the IsLessThanFilterRule class.
21+
/// Initializes a new instance of the <see cref="IsLessThanFilterRule{T}"/> class.
2222
/// </summary>
2323
public IsLessThanFilterRule()
2424
{
2525
this.DisplayName = UICultureResources.FilterRule_LessThanOrEqual;
2626
}
2727

28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="IsLessThanFilterRule{T}"/> class.
30+
/// </summary>
31+
/// <param name="source">The source to initialize from.</param>
32+
public IsLessThanFilterRule(IsLessThanFilterRule<T> source)
33+
: base(source)
34+
{
35+
}
36+
2837
/// <summary>
2938
/// Determines if item is less than Value.
3039
/// </summary>

src/Microsoft.Management.UI.Internal/ManagementList/FilterCore/FilterRules/IsNotEmptyFilterRule.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@ namespace Microsoft.Management.UI.Internal
1414
public class IsNotEmptyFilterRule : IsEmptyFilterRule
1515
{
1616
/// <summary>
17-
/// Initializes a new instance of the IsNotEmptyFilterRule class.
17+
/// Initializes a new instance of the <see cref="IsNotEmptyFilterRule"/> class.
1818
/// </summary>
1919
public IsNotEmptyFilterRule()
2020
{
2121
this.DisplayName = UICultureResources.FilterRule_IsNotEmpty;
2222
}
2323

24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="IsNotEmptyFilterRule"/> class.
26+
/// </summary>
27+
/// <param name="source">The source to initialize from.</param>
28+
public IsNotEmptyFilterRule(IsNotEmptyFilterRule source)
29+
: base(source)
30+
{
31+
}
32+
2433
/// <summary>
2534
/// Gets a values indicating whether the supplied item is not empty.
2635
/// </summary>

0 commit comments

Comments
 (0)