Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit 13e0d34

Browse files
authored
Do not use reflection in FeatureSwitch #603 (#605)
1 parent 64b2460 commit 13e0d34

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

ClickHouse.Client/FeatureSwitch.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
using System;
2-
using System.Linq;
1+
using System;
32

4-
namespace ClickHouse.Client;
5-
6-
internal class FeatureSwitch
3+
namespace ClickHouse.Client
74
{
8-
private const string Prefix = "ClickHouse.Client.";
5+
internal class FeatureSwitch
6+
{
7+
private const string Prefix = "ClickHouse.Client.";
98

10-
// Field names are used as switch
11-
public static readonly bool DisableReplacingParameters;
9+
public static readonly bool DisableReplacingParameters;
1210

13-
static FeatureSwitch()
14-
{
15-
var fields = typeof(FeatureSwitch).GetFields().Where(f => f.FieldType == typeof(bool));
16-
foreach (var field in fields)
11+
static FeatureSwitch()
12+
{
13+
DisableReplacingParameters = GetSwitchValue(nameof(DisableReplacingParameters));
14+
}
15+
16+
private static bool GetSwitchValue(string switchName)
1717
{
18-
var switchName = Prefix + field.Name;
19-
AppContext.TryGetSwitch(switchName, out bool switchValue);
20-
field.SetValue(null, switchValue);
18+
AppContext.TryGetSwitch(Prefix + switchName, out bool switchValue);
19+
return switchValue;
2120
}
2221
}
2322
}

0 commit comments

Comments
 (0)