You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by la...@apache.org on 2023/04/09 12:58:24 UTC
[lucenenet] branch master updated: BREAKING: remove virtual call from the constructor for Sort (#813)
This is an automated email from the ASF dual-hosted git repository.
laimis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
The following commit(s) were added to refs/heads/master by this push:
new 3846ec41a BREAKING: remove virtual call from the constructor for Sort (#813)
3846ec41a is described below
commit 3846ec41ae36e10ff37d934753615e1a483900af
Author: Laimonas Simutis <la...@gmail.com>
AuthorDate: Sun Apr 9 05:58:17 2023 -0700
BREAKING: remove virtual call from the constructor for Sort (#813)
---
src/Lucene.Net/Search/Sort.cs | 37 ++++++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/Lucene.Net/Search/Sort.cs b/src/Lucene.Net/Search/Sort.cs
index 55e6b75b9..db18a29ab 100644
--- a/src/Lucene.Net/Search/Sort.cs
+++ b/src/Lucene.Net/Search/Sort.cs
@@ -128,27 +128,38 @@ namespace Lucene.Net.Search
/// Sorts by the criteria in the given <see cref="SortField"/>. </summary>
public Sort(SortField field)
{
- SetSort(field);
+ SetSortInternal(field); // LUCENENET specific - calling private instead of virtual method
}
/// <summary>
- /// Sorts in succession by the criteria in each <see cref="SortField"/>. </summary>
+ /// Sorts in succession by the criteria in each <see cref="SortField"/>.
+ /// </summary>
public Sort(params SortField[] fields)
{
- SetSort(fields);
+ SetSortInternal(fields); // LUCENENET specific - calling private instead of virtual method
}
- /// <summary>Sets the sort to the given criteria. </summary>
- public virtual void SetSort(SortField field)
- {
- this.fields = new SortField[] { field };
- }
+ /// <summary>
+ /// Sets the sort to the given criteria.
+ ///
+ /// NOTE: When overriding this method, be aware that the constructor of this class calls
+ /// a private method and not this virtual method. So if you need to override
+ /// the behavior during the initialization, call your own private method from the constructor
+ /// with whatever custom behavior you need.
+ /// </summary>
+ public virtual void SetSort(SortField field) => SetSortInternal(field);
- /// <summary>Sets the sort to the given criteria in succession. </summary>
- public virtual void SetSort(params SortField[] fields)
- {
- this.fields = fields;
- }
+ /// <summary>
+ /// Sets the sort to the given criteria in succession.
+ ///
+ /// NOTE: When overriding this method, be aware that the constructor of this class calls
+ /// a private method and not this virtual method. So if you need to override
+ /// the behavior during the initialization, call your own private method from the constructor
+ /// with whatever custom behavior you need.
+ /// </summary>
+ public virtual void SetSort(params SortField[] fields) => SetSortInternal(fields);
+
+ private void SetSortInternal(params SortField[] fields) => this.fields = fields;
/// <summary> Representation of the sort criteria.</summary>
/// <returns> Array of <see cref="SortField"/> objects used in this sort criteria