lucenenet icon indicating copy to clipboard operation
lucenenet copied to clipboard

Change 'static readonly' fields to 'const', where appropriate

Open NightOwl888 opened this issue 1 year ago • 0 comments

For private fields that are either primitive type or string, we can simply change these to const with no ill effects (which can be its own PR).

For internal/public/protected fields, generally the answer is yes, we should change these. However, changing to const means compiling the value into a consuming assemblies' metadata, so we need to be judicious on how to deal with these.

  1. If the value will certainly never change, we can change to const.
  2. If the value is likely to change, we should leave as static readonly.
  3. All other cases need to be considered carefully.

For example, we need to consider the implications of what will happen if someone uses an older version of one of the modules, such as Lucene.Net.Analysis.Common with a newer version of Lucene.Net that has updates to these constant values. If there is any doubt, these should be static readonly.

Do note that making this change may result in compile errors which means we need to either revert the change or apply a fix, if appropriate.

NOTE: In Java, there is only one option, static final, so this is a .NET-specific translation problem and there is no need to add a // LUCENENET comment for it.

NightOwl888 avatar Oct 15 '22 10:10 NightOwl888