-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Hosts] Improved duplicate hosts finding (#24294)
* improved duplicate hosts finding * improved filters with AdvancedCollectionView * cancel FindDuplicates when file is reloaded
- Loading branch information
1 parent
0d9b797
commit 3e651b8
Showing
14 changed files
with
290 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace Hosts.Helpers | ||
{ | ||
// https://stackoverflow.com/a/22569086 | ||
public static class ExpressionExtensions | ||
{ | ||
public static Expression<Func<T, bool>> And<T>( | ||
this Expression<Func<T, bool>> expr1, | ||
Expression<Func<T, bool>> expr2) | ||
{ | ||
var secondBody = expr2.Body.Replace(expr2.Parameters[0], expr1.Parameters[0]); | ||
return Expression.Lambda<Func<T, bool>>(Expression.AndAlso(expr1.Body, secondBody), expr1.Parameters); | ||
} | ||
|
||
public static Expression Replace(this Expression expression, Expression searchEx, Expression replaceEx) | ||
{ | ||
return new ReplaceVisitor(searchEx, replaceEx).Visit(expression); | ||
} | ||
|
||
internal class ReplaceVisitor : ExpressionVisitor | ||
{ | ||
private readonly Expression _from; | ||
private readonly Expression _to; | ||
|
||
public ReplaceVisitor(Expression from, Expression to) | ||
{ | ||
_from = from; | ||
_to = to; | ||
} | ||
|
||
public override Expression Visit(Expression node) | ||
{ | ||
return node == _from ? _to : base.Visit(node); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Hosts.Models | ||
{ | ||
public enum AddressType | ||
{ | ||
Invalid = 0, | ||
IPv4 = 1, | ||
IPv6 = 2, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.