8000 Fix Out-GridView by replacing use of obsolete BinaryFormatter with custom implementation. by mawosoft · Pull Request #25497 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fix Out-GridView by replacing use of obsolete BinaryFormatter with custom implementation. #25497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ namespace Microsoft.Management.UI.Internal
[Serializable]
public abstract class ComparableValueFilterRule<T> : FilterRule where T : IComparable
{
/// <summary>
/// Initializes a new instance of the <see cref="ComparableValueFilterRule{T}"/> class.
/// </summary>
protected ComparableValueFilterRule()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ComparableValueFilterRule{T}"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
protected ComparableValueFilterRule(ComparableValueFilterRule<T> source)
: base(source)
{
this.DefaultNullValueEvaluation = source.DefaultNullValueEvaluation;
}

#region Properties

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ namespace Microsoft.Management.UI.Internal
public class DoesNotEqualFilterRule<T> : EqualsFilterRule<T> where T : IComparable
{
/// <summary>
/// Initializes a new instance of the DoesNotEqualFilterRule class.
/// Initializes a new instance of the <see cref="DoesNotEqualFilterRule{T}"/> class.
/// </summary>
public DoesNotEqualFilterRule()
{
this.DisplayName = UICultureResources.FilterRule_DoesNotEqual;
this.DefaultNullValueEvaluation = true;
}

/// <summary>
/// Initializes a new instance of the <see cref="DoesNotEqualFilterRule{T}"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public DoesNotEqualFilterRule(DoesNotEqualFilterRule<T> source)
: base(source)
{
}

/// <summary>
/// Determines if item is not equal to Value.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ namespace Microsoft.Management.UI.Internal
public class EqualsFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
{
/// <summary>
/// Initializes a new instance of the EqualsFilterRule class.
/// Initializes a new instance of the <see cref="EqualsFilterRule{T}"/> class.
/// </summary>
public EqualsFilterRule()
{
this.DisplayName = UICultureResources.FilterRule_Equals;
}

/// <summary>
/// Initializes a new instance of the <see cref="EqualsFilterRule{T}"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public EqualsFilterRule(EqualsFilterRule<T> source)
: base(source)
{
}

/// <summary>
/// Determines if item is equal to Value.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Management.UI.Internal
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes")]
[Serializable]
public abstract class FilterRule : IEvaluate
public abstract class FilterRule : IEvaluate, IDeepCloneable
{
/// <summary>
/// Gets a value indicating whether the FilterRule can be
Expand All @@ -34,12 +34,28 @@ public string DisplayName
}

/// <summary>
/// Initializes a new instance of the FilterRule class.
/// Initializes a new instance of the <see cref="FilterRule"/> class.
/// </summary>
protected FilterRule()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="FilterRule"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
protected FilterRule(FilterRule source)
{
ArgumentNullException.ThrowIfNull(source);
this.DisplayName = source.DisplayName;
}

/// <inheritdoc cref="IDeepCloneable.DeepClone()" />
public object DeepClone()
{
return Activator.CreateInstance(this.GetType(), new object[] { this });
}

/// <summary>
/// Gets a value indicating whether the supplied item meets the
/// criteria specified by this rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace Microsoft.Management.UI.Internal
{
8000 Expand All @@ -28,29 +24,7 @@ public static class FilterRuleExtensions
public static FilterRule DeepCopy(this FilterRule rule)
{
ArgumentNullException.ThrowIfNull(rule);

#pragma warning disable SYSLIB0050
Debug.Assert(rule.GetType().IsSerializable, "rule is serializable");
#pragma warning disable SYSLIB0011
BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.Clone));
#pragma warning restore SYSLIB0011
MemoryStream ms = new MemoryStream();

FilterRule copy = null;
try
{
formatter.Serialize(ms, rule);

ms.Position = 0;
copy = (FilterRule)formatter.Deserialize(ms);
#pragma warning restore SYSLIB0050
}
finally
{
ms.Close();
}

return copy;
return (FilterRule)rule.DeepClone();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ValidatingValue<T> EndValue
#region Ctor

/// <summary>
/// Initializes a new instance of the IsBetweenFilterRule class.
/// Initializes a new instance of the <see cref="IsBetweenFilterRule{T}"/> class.
/// </summary>
public IsBetweenFilterRule()
{
Expand All @@ -69,6 +69,20 @@ public IsBetweenFilterRule()
this.EndValue.PropertyChanged += this.Value_PropertyChanged;
}

/// <summary>
/// Initializes a new instance of the <see cref="IsBetweenFilterRule{T}"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public IsBetweenFilterRule(IsBetweenFilterRule<T> source)
: base(source)
{
this.StartValue = (ValidatingValue<T>)source.StartValue.DeepClone();
this.StartValue.PropertyChanged += this.Value_PropertyChanged;

this.EndValue = (ValidatingValue<T>)source.EndValue.DeepClone();
this.EndValue.PropertyChanged += this.Value_PropertyChanged;
}

#endregion Ctor

#region Public Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ namespace Microsoft.Management.UI.Internal
public class IsEmptyFilterRule : FilterRule
{
/// <summary>
/// Initializes a new instance of the IsEmptyFilterRule class.
/// Initializes a new instance of the <see cref="IsEmptyFilterRule"/> class.
/// </summary>
public IsEmptyFilterRule()
{
this.DisplayName = UICultureResources.FilterRule_IsEmpty;
}

/// <summary>
/// Initializes a new instance of the <see cref="IsEmptyFilterRule"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public IsEmptyFilterRule(IsEmptyFilterRule source)
: base(source)
{
}

/// <summary>
/// Gets a values indicating whether the supplied item is empty.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ namespace Microsoft.Management.UI.Internal
public class IsGreaterThanFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
{
/// <summary>
/// Initializes a new instance of the IsGreaterThanFilterRule class.
/// Initializes a new instance of the <see cref="IsGreaterThanFilterRule{T}"/> class.
/// </summary>
public IsGreaterThanFilterRule()
{
this.DisplayName = UICultureResources.FilterRule_GreaterThanOrEqual;
}

/// <summary>
/// Initializes a new instance of the <see cref="IsGreaterThanFilterRule{T}"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public IsGreaterThanFilterRule(IsGreaterThanFilterRule<T> source)
: base(source)
{
}

/// <summary>
/// Determines if item is greater than Value.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ namespace Microsoft.Management.UI.Internal
public class IsLessThanFilterRule<T> : SingleValueComparableValueFilterRule<T> where T : IComparable
{
/// <summary>
/// Initializes a new instance of the IsLessThanFilterRule class.
/// Initializes a new instance of the <see cref="IsLessThanFilterRule{T}"/> class.
/// </summary>
public IsLessThanFilterRule()
{
this.DisplayName = UICultureResources.FilterRule_LessThanOrEqual;
}

/// <summary>
/// Initializes a new instance of the <see cref="IsLessThanFilterRule{T}"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public IsLessThanFilterRule(IsLessThanFilterRule<T> source)
: base(source)
{
}

/// <summary>
/// Determines if item is less than Value.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ namespace Microsoft.Management.UI.Internal
public class IsNotEmptyFilterRule : IsEmptyFilterRule
{
/// <summary>
/// Initializes a new instance of the IsNotEmptyFilterRule class.
/// Initializes a new instance of the <see cref="IsNotEmptyFilterRule"/> class.
/// </summary>
public IsNotEmptyFilterRule()
{
this.DisplayName = UICultureResources.FilterRule_IsNotEmpty;
}

/// <summary>
/// Initializes a new instance of the <see cref="IsNotEmptyFilterRule"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public IsNotEmptyFilterRule(IsNotEmptyFilterRule source)
: base(source)
{
}

/// <summary>
/// Gets a values indicating whether the supplied item is not empty.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public override DataErrorInfoValidationResult Validate(object value, System.Glob
}
}

/// <inheritdoc cref="IDeepCloneable.DeepClone()" />
public override object DeepClone()
{
// Instance is stateless.
// return this;
return new IsNotEmptyValidationRule();
}

#endregion Public Methods

internal static bool IsStringNotEmpty(string value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ public PropertiesTextContainsFilterRule()
this.EvaluationResultInvalidated += this.PropertiesTextContainsFilterRule_EvaluationResultInvalidated;
}

/// <summary>
/// Initializes a new instance of the <see cref="PropertiesTextContainsFilterRule"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public PropertiesTextContainsFilterRule(PropertiesTextContainsFilterRule source)
: base(source)
{
this.PropertyNames = new List<string>(source.PropertyNames);
this.EvaluationResultInvalidated += this.PropertiesTextContainsFilterRule_EvaluationResultInvalidated;
}

/// <summary>
/// Gets a collection of the names of properties to search in.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ public PropertyValueSelectorFilterRule(string propertyName, string propertyDispl
this.AvailableRules.DisplayNameConverter = new FilterRuleToDisplayNameConverter();
}

/// <summary>
/// Initializes a new instance of the <see cref="PropertyValueSelectorFilterRule{T}"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public PropertyValueSelectorFilterRule(PropertyValueSelectorFilterRule<T> source)
: base(source)
{
this.PropertyName = source.PropertyName;
this.AvailableRules.DisplayNameConverter = new FilterRuleToDisplayNameConverter();
}

#endregion Ctor

#region Public Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,26 @@ public ValidatingSelectorValue<FilterRule> AvailableRules
#region Ctor

/// <summary>
/// Creates a new SelectorFilterRule instance.
/// Initializes a new instance of the <see cref="SelectorFilterRule"/> class.
/// </summary>
public SelectorFilterRule()
{
this.AvailableRules = new ValidatingSelectorValue<FilterRule>();
this.AvailableRules.SelectedValueChanged += this.AvailableRules_SelectedValueChanged;
}

/// <summary>
/// Initializes a new instance of the <see cref="SelectorFilterRule"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
public SelectorFilterRule(SelectorFilterRule source)
: base(source)
{
this.AvailableRules = (ValidatingSelectorValue<FilterRule>)source.AvailableRules.DeepClone();
this.AvailableRules.SelectedValueChanged += this.AvailableRules_SelectedValueChanged;
this.AvailableRules.SelectedValue.EvaluationResultInvalidated += this.SelectedValue_EvaluationResultInvalidated;
}

#endregion Ctor

#region Public Methods
Expand Down Expand Up @@ -86,8 +98,8 @@ protected void OnSelectedValueChanged(FilterRule oldValue, FilterRule newValue)
FilterRuleCustomizationFactory.FactoryInstance.TransferValues(oldValue, newValue);
FilterRuleCustomizationFactory.FactoryInstance.ClearValues(oldValue);

newValue.EvaluationResultInvalidated += this.SelectedValue_EvaluationResultInvalidated;
oldValue.EvaluationResultInvalidated -= this.SelectedValue_EvaluationResultInvalidated;
newValue.EvaluationResultInvalidated += this.SelectedValue_EvaluationResultInvalidated;

this.NotifyEvaluationResultInvalidated();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,25 @@ public override bool IsValid
#region Ctor

/// <summary>
/// Initializes a new instance of the SingleValueComparableValueFilterRule class.
/// Initializes a new instance of the <see cref="SingleValueComparableValueFilterRule{T}"/> class.
/// </summary>
protected SingleValueComparableValueFilterRule()
{
this.Value = new ValidatingValue<T>();
this.Value.PropertyChanged += this.Value_PropertyChanged;
}

/// <summary>
/// Initializes a new instance of the <see cref="SingleValueComparableValueFilterRule{T}"/> class.
/// </summary>
/// <param name="source">The source to initialize from.</param>
protected SingleValueComparableValueFilterRule(SingleValueComparableValueFilterRule<T> source)
: base(source)
{
this.Value = (ValidatingValue<T>)source.Value.DeepClone();
this.Value.PropertyChanged += this.Value_PropertyChanged;
}

#endregion Ctor

private void Value_PropertyChanged(object sender, PropertyChangedEventArgs e)
Expand Down
Loading
Loading
0