Skip to content

Commit e5ca209

Browse files
committed
Generate Map/Switch if the number of items is less than 1000
1 parent 7ecd860 commit e5ca209

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Copyright>(c) $([System.DateTime]::Now.Year), Pawel Gerr. All rights reserved.</Copyright>
5-
<VersionPrefix>6.5.1</VersionPrefix>
5+
<VersionPrefix>6.5.2</VersionPrefix>
66
<Authors>Pawel Gerr</Authors>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<PackageProjectUrl>https://github.com/PawelGerr/Thinktecture.Runtime.Extensions</PackageProjectUrl>

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/SmartEnums/AllEnumSettings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public sealed class AllEnumSettings : IEquatable<AllEnumSettings>
1212
public OperatorsGeneration EqualityComparisonOperators { get; }
1313
public bool SkipIFormattable { get; }
1414
public bool SkipToString { get; }
15-
public bool SkipSwitchMethods { get; }
16-
public bool SkipMapMethods { get; }
15+
public bool? SkipSwitchMethods { get; }
16+
public bool? SkipMapMethods { get; }
1717

1818
public AllEnumSettings(AttributeData? attribute, bool isValidatable)
1919
{
@@ -25,8 +25,8 @@ public AllEnumSettings(AttributeData? attribute, bool isValidatable)
2525
EqualityComparisonOperators = attribute?.FindEqualityComparisonOperators() ?? OperatorsGeneration.Default;
2626
SkipIFormattable = attribute?.FindSkipIFormattable() ?? false;
2727
SkipToString = attribute?.FindSkipToString() ?? false;
28-
SkipSwitchMethods = attribute?.FindSkipSwitchMethods() ?? false;
29-
SkipMapMethods = attribute?.FindSkipMapMethods() ?? false;
28+
SkipSwitchMethods = attribute?.FindSkipSwitchMethods();
29+
SkipMapMethods = attribute?.FindSkipMapMethods();
3030

3131
// Comparison operators depend on the equality comparison operators
3232
if (ComparisonOperators > EqualityComparisonOperators)

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/SmartEnums/EnumSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace Thinktecture.CodeAnalysis.SmartEnums;
77

88
public bool IsValidatable => _settings.IsValidatable;
99
public bool SkipToString => _settings.SkipToString;
10-
public bool SkipSwitchMethods => _settings.SkipSwitchMethods;
11-
public bool SkipMapMethods => _settings.SkipMapMethods;
10+
public bool? SkipSwitchMethods => _settings.SkipSwitchMethods;
11+
public bool? SkipMapMethods => _settings.SkipMapMethods;
1212
public bool HasStructLayoutAttribute => _attributeInfo.HasStructLayoutAttribute;
1313
public IReadOnlyList<DesiredFactory> DesiredFactories => _attributeInfo.DesiredFactories;
1414

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/SmartEnums/SmartEnumCodeGenerator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,17 @@ public override int GetHashCode()
166166
if (!_state.Settings.SkipToString)
167167
GenerateToString();
168168

169-
if (!_state.Settings.SkipSwitchMethods)
169+
var hasSaneNumberOfItems = _state.ItemNames.Count < 1000;
170+
171+
if (!_state.Settings.SkipSwitchMethods.GetValueOrDefault() && hasSaneNumberOfItems)
170172
{
171173
GenerateSwitchForAction(false);
172174
GenerateSwitchForAction(true);
173175
GenerateSwitchForFunc(false);
174176
GenerateSwitchForFunc(true);
175177
}
176178

177-
if (!_state.Settings.SkipMapMethods)
179+
if (!_state.Settings.SkipMapMethods.GetValueOrDefault() && hasSaneNumberOfItems)
178180
GenerateMap();
179181

180182
GenerateGetLookup();

0 commit comments

Comments
 (0)