10000 Revert changes to continue using `BinaryFormatter` for `Out-GridView`… · PowerShell/PowerShell@d2b3ff7 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2b3ff7

Browse files
authored
Revert changes to continue using BinaryFormatter for Out-GridView (#20300)
1 parent e2ca8fe commit d2b3ff7

29 files changed

+52
-263
lines changed

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

+1-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Microsoft.Management.UI.Internal
1313
/// The generic parameter.
1414
/// </typeparam>
1515
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
16+
[Serializable]
1617
public abstract class ComparableValueFilterRule<T> : FilterRule where T : IComparable
1718
{
1819
#region Properties
@@ -61,19 +62,6 @@ public override bool Evaluate(object item)
6162
return this.Evaluate(castItem);
6263
}
6364

64-
/// <summary>
65-
/// Creates a clone of the ComparableValueFilterRule instance.
66-
/// </summary>
67-
/// <returns>
68-
/// Returns a clone of the ComparableValueFilterRule instance.
69-
/// </returns>
70-
public override FilterRule Clone()
71-
{
72-
ComparableValueFilterRule<T> rule = (ComparableValueFilterRule<T>)Activator.CreateInstance(this.GetType());
73-
rule.DefaultNullValueEvaluation = this.DefaultNullValueEvaluation;
74-
return rule;
75-
}
76-
7765
/// <summary>
7866
/// Determines if item matches a derived classes criteria.
7967
/// </summary>

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

+1-14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Microsoft.Management.UI.Internal
1313
/// The generic parameter.
1414
/// </typeparam>
1515
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
16+
[Serializable]
1617
public class DoesNotEqualFilterRule<T> : EqualsFilterRule<T> where T : IComparable
1718
{
1819
/// <summary>
@@ -24,20 +25,6 @@ public DoesNotEqualFilterRule()
2425
this.DefaultNullValueEvaluation = true;
2526
}
2627

27-
/// <summary>
28-
/// Creates a clone of the DoesNotEqualFilterRule instance.
29-
/// </summary>
30-
/// <returns>
31-
/// A clone of the DoesNotEqualFilterRule instance.
32-
/// </returns>
33-
public override FilterRule Clone()
34-
{
35-
DoesNotEqualFilterRule<T> rule = new DoesNotEqualFilterRule<T>();
36-
rule.Value = this.Value;
37-
rule.DefaultNullValueEvaluation = this.DefaultNullValueEvaluation;
38-
return rule;
39-
}
40-
4128
/// <summary>
4229
/// Determines if item is not equal to Value.
4330
/// </summary>

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

+1-14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Management.UI.Internal
1414
/// The generic parameter.
1515
/// </typeparam>
1616
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
17+
[Serializable]
1718
public class EqualsFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
1819
{
1920
/// <summary>
@@ -24,20 +25,6 @@ public EqualsFilterRule()
2425
this.DisplayName = UICultureResources.FilterRule_Equals;
2526
}
2627

27-
/// <summary>
28-
/// Creates a new EqualsFilterRule that is a clone of the current instance.
29-
/// </summary>
30-
/// <returns>
31-
/// A new EqualsFilterRule that is a clone of the current instance.
32-
/// </returns>
33-
public override FilterRule Clone()
34-
{
35-
EqualsFilterRule<T> rule = new EqualsFilterRule<T>();
36-
rule.Value = this.Value;
37-
rule.DefaultNullValueEvaluation = this.DefaultNullValueEvaluation;
38-
return rule;
39-
}
40-
4128
/// <summary>
4229
/// Determines if item is equal to Value.
4330
/// </summary>

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Microsoft.Management.UI.Internal
1010
/// The base class for all filtering rules.
1111
/// </summary>
1212
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
13+
[Serializable]
1314
public abstract class FilterRule : IEvaluate
1415
{
1516
/// <summary>
@@ -48,12 +49,6 @@ protected FilterRule()
4849
/// <returns>Returns true if the item meets the criteria. False otherwise.</returns>
4950
public abstract bool Evaluate(object item);
5051

51-
/// <summary>
52-
/// Creates a clone of this FilterRule.
53-
/// </summary>
54-
/// <returns>Returns a clone of this FilterRule.</returns>
55-
public abstract FilterRule Clone();
56-
5752
#region EvaluationResultInvalidated
5853

5954
/// <summary>

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,30 @@ public static class FilterRuleExtensions
2727
/// </returns>
2828
public static FilterRule DeepCopy(this FilterRule rule)
2929
{
30-
return rule.Clone();
30+
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;
3154
}
3255
}
3356
}

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

+1-15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Microsoft.Management.UI.Internal
1616
/// The generic parameter.
1717
/// </typeparam>
1818
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
19+
[Serializable]
1920
public class IsBetweenFilterRule<T> : ComparableValueFilterRule<T> where T : IComparable
2021
{
2122
#region Properties
@@ -50,21 +51,6 @@ public ValidatingValue<T> EndValue
5051
protected set;
5152
}
5253

53-
/// <summary>
54-
/// Creates a clone of the FilterRule.
55-
/// </summary>
56-
/// <returns>
57-
/// A clone of the FilterRule.
58-
/// </returns>
59-
public override FilterRule Clone()
60-
{
61-
IsBetweenFilterRule<T> clone = new IsBetweenFilterRule<T>();
62-
clone.DefaultNullValueEvaluation = this.DefaultNullValueEvaluation;
63-
clone.StartValue = this.StartValue;
64-
clone.EndValue = this.EndValue;
65-
return clone;
66-
}
67-
6854
#endregion Properties
6955

7056
#region Ctor

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Microsoft.Management.UI.Internal
1010
/// is empty or not.
1111
/// </summary>
1212
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
13+
[Serializable]
1314
public class IsEmptyFilterRule : FilterRule
1415
{
1516
/// <summary>
@@ -20,18 +21,6 @@ public IsEmptyFilterRule()
2021
this.DisplayName = UICultureResources.FilterRule_IsEmpty;
2122
}
2223

23-
/// <summary>
24-
/// Creates a clone of the IsEmptyFilterRule instance.
25-
/// </summary>
26-
/// <returns>
27-
/// A clone of IsEmptyFilterRule instance.
28-
/// </returns>
29-
public override FilterRule Clone()
30-
{
31-
IsEmptyFilterRule rule = new IsEmptyFilterRule();
32-
return rule;
33-
}
34-
3524
/// <summary>
3625
/// Gets a values indicating whether the supplied item is empty.
3726
/// </summary>

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

+1-14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Management.UI.Internal
1414
/// The generic parameter.
1515
/// </typeparam>
1616
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
17+
[Serializable]
1718
public class IsGreaterThanFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
1819
{
1920
/// <summary>
@@ -24,20 +25,6 @@ public IsGreaterThanFilterRule()
2425
this.DisplayName = UICultureResources.FilterRule_GreaterThanOrEqual;
2526
}
2627

27-
/// <summary>
28-
/// Creates a new IsGreaterThanFilterRule that is a clone of the current instance.
29-
/// </summary>
30-
/// <returns>
31-
/// A new IsGreaterThanFilterRule that is a clone of the current instance.
32-
/// </returns>
33-
public override FilterRule Clone()
34-
{
35-
IsGreaterThanFilterRule<T> rule = new IsGreaterThanFilterRule<T>();
36-
rule.Value = this.Value;
37-
rule.DefaultNullValueEvaluation = this.DefaultNullValueEvaluation;
38-
return rule;
39-
}
40-
4128
/// <summary>
4229
/// Determines if item is greater than Value.
4330
/// </summary>

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

+1-14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Management.UI.Internal
1414
/// The generic parameter.
1515
/// </typeparam>
1616
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
17+
[Serializable]
1718
public class IsLessThanFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
1819
{
1920
/// <summary>
@@ -24,20 +25,6 @@ public IsLessThanFilterRule()
2425
this.DisplayName = UICultureResources.FilterRule_LessThanOrEqual;
2526
}
2627

27-
/// <summary>
28-
/// Creates a new IsLessThanFilterRule that is a clone of the current instance.
29-
/// </summary>
30-
/// <returns>
31-
/// A new IsLessThanFilterRule that is a clone of the current instance.
32-
/// </returns>
33-
public override FilterRule Clone()
34-
{
35-
IsLessThanFilterRule<T> rule = new IsLessThanFilterRule<T>();
36-
rule.Value = this.Value;
37-
rule.DefaultNullValueEvaluation = this.DefaultNullValueEvaluation;
38-
return rule;
39-
}
40-
4128
/// <summary>
4229
/// Determines if item is less than Value.
4330
/// </summary>

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Microsoft.Management.UI.Internal
1010
/// is empty or not.
1111
/// </summary>
1212
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
13+
[Serializable]
1314
public class IsNotEmptyFilterRule : IsEmptyFilterRule
1415
{
1516
/// <summary>
@@ -20,18 +21,6 @@ public IsNotEmptyFilterRule()
2021
this.DisplayName = UICultureResources.FilterRule_IsNotEmpty;
2122
}
2223

23-
/// <summary>
24-
/// Creates a clone of the IsNotEmptyFilterRule.
25-
/// </summary>
26-
/// <returns>
27-
/// A clone of the IsNotEmptyFilterRule.
28-
/// </returns>
29-
public override FilterRule Clone()
30-
{
31-
IsNotEmptyFilterRule rule = new IsNotEmptyFilterRule();
32-
return rule;
33-
}
34-
3524
/// <summary>
3625
/// Gets a values indicating whether the supplied item is not empty.
3726
/// </summary>

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

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.Management.UI.Internal
99
/// The IsNotEmptyValidationRule checks a value to see if a value is not empty.
1010
/// </summary>
1111
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
12+
[Serializable]
1213
public class IsNotEmptyValidationRule : DataErrorInfoValidationRule
1314
{
1415
#region Properties

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

+1-14
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Microsoft.Management.UI.Internal
1212
/// Represents a filter rule that searches for text within properties on an object.
1313
/// </summary>
1414
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
15+
[Serializable]
1516
public class PropertiesTextContainsFilterRule : TextFilterRule
1617
{
1718
private static readonly string TextContainsCharactersRegexPattern = "{0}";
@@ -37,20 +38,6 @@ public ICollection<string> PropertyNames
3738
private set;
3839
}
3940

40-
/// <summary>
41-
/// Creates a clone of this <see cref="PropertiesTextContainsFilterRule"/>.
42-
/// </summary>
43-
/// <returns>
44-
/// A clone of this <see cref="PropertiesTextContainsFilterRule"/>.
45-
/// </returns>
46-
public override FilterRule Clone()
47-
{
48-
PropertiesTextContainsFilterRule clone = new PropertiesTextContainsFilterRule();
49-
clone.DefaultNullValueEvaluation = this.DefaultNullValueEvaluation;
50-
clone.PropertyNames = new List<string>(this.PropertyNames);
51-
return clone;
52-
}
53-
5441
/// <summary>
5542
/// Evaluates whether the specified properties on <paramref name="item"/> contain the current value.
5643
/// </summary>

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

+1-16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Microsoft.Management.UI.Internal
1616
/// The generic parameter.
1717
/// </typeparam>
1818
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
19+
[Serializable]
1920
public class PropertyValueSelectorFilterRule<T> : SelectorFilterRule where T : IComparable
2021
{
2122
#region Properties
@@ -65,11 +66,6 @@ public PropertyValueSelectorFilterRule(string propertyName, string propertyDispl
6566
/// </param>
6667
public PropertyValueSelectorFilterRule(string propertyName, string propertyDisplayName, IEnumerable<FilterRule> rules)
6768
{
68-
ArgumentException.ThrowIfNullOrEmpty(propertyName);
69-
ArgumentException.ThrowIfNullOrEmpty(propertyDisplayName);
70-
71-
ArgumentNullException.ThrowIfNull(rules);
72-
7369
this.PropertyName = propertyName;
7470
this.DisplayName = propertyDisplayName;
7571

@@ -120,17 +116,6 @@ public override bool Evaluate(object item)
120116
return this.AvailableRules.SelectedValue.Evaluate(propertyValue);
121117
}
122118

123-
/// <summary>
124-
/// Creates a clone of the PropertyValueSelectorFilterRule instance.
125-
/// </summary>
126-
/// <returns>
127-
/// Returns a clone of the PropertyValueSelectorFilterRule instance.
128-
/// </returns>
129-
public override FilterRule Clone()
130-
{
131-
return new PropertyValueSelectorFilterRule<T>(this.PropertyName, this.DisplayName, this.AvailableRules.AvailableValues);
132-
}
133-
134119
#endregion Public Methods
135120

136121
#region Private Methods

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

+1-17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Microsoft.Management.UI.Internal
1010
/// The SelectorFilterRule represents a rule composed of other rules.
1111
/// </summary>
1212
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
13+
[Serializable]
1314
public class SelectorFilterRule : FilterRule
1415
{
1516
#region Properties
@@ -70,23 +71,6 @@ public override bool Evaluate(object item)
7071
return this.AvailableRules.SelectedValue.Evaluate(item);
7172
}
7273

73-
/// <summary>
74-
/// Creates a clone of the SelectorFilterRule instance.
75-
/// </summary>
76-
/// <returns>
77-
/// Returns a clone of the SelectorFilterRule instance.
78-
/// </returns>
79-
public override FilterRule Clone()
80-
{
81-
SelectorFilterRule clone = new SelectorFilterRule();
82-
clone.DisplayName = this.DisplayName;
83-
clone.AvailableRules = this.AvailableRules;
84-
clone.AvailableRules.SelectedValueChanged += clone.AvailableRules_SelectedValueChanged;
85-
clone.AvailableRules.SelectedValue.EvaluationResultInvalidated += clone.SelectedValue_EvaluationResultInvalidated;
86-
87-
return clone;
88-
}
89-
9074
/// <summary>
9175
/// Called when the SelectedValue within AvailableRules changes.
9276
/// </summary>

0 commit comments

Comments
 (0)
0