Skip to content

Commit

Permalink
Generate Map/Switch if the number of items is less than 1000
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGerr committed Nov 17, 2023
1 parent 7ecd860 commit e5ca209
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Copyright>(c) $([System.DateTime]::Now.Year), Pawel Gerr. All rights reserved.</Copyright>
<VersionPrefix>6.5.1</VersionPrefix>
<VersionPrefix>6.5.2</VersionPrefix>
<Authors>Pawel Gerr</Authors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageProjectUrl>https://github.com/PawelGerr/Thinktecture.Runtime.Extensions</PackageProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public sealed class AllEnumSettings : IEquatable<AllEnumSettings>
public OperatorsGeneration EqualityComparisonOperators { get; }
public bool SkipIFormattable { get; }
public bool SkipToString { get; }
public bool SkipSwitchMethods { get; }
public bool SkipMapMethods { get; }
public bool? SkipSwitchMethods { get; }
public bool? SkipMapMethods { get; }

public AllEnumSettings(AttributeData? attribute, bool isValidatable)
{
Expand All @@ -25,8 +25,8 @@ public AllEnumSettings(AttributeData? attribute, bool isValidatable)
EqualityComparisonOperators = attribute?.FindEqualityComparisonOperators() ?? OperatorsGeneration.Default;
SkipIFormattable = attribute?.FindSkipIFormattable() ?? false;
SkipToString = attribute?.FindSkipToString() ?? false;
SkipSwitchMethods = attribute?.FindSkipSwitchMethods() ?? false;
SkipMapMethods = attribute?.FindSkipMapMethods() ?? false;
SkipSwitchMethods = attribute?.FindSkipSwitchMethods();
SkipMapMethods = attribute?.FindSkipMapMethods();

// Comparison operators depend on the equality comparison operators
if (ComparisonOperators > EqualityComparisonOperators)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace Thinktecture.CodeAnalysis.SmartEnums;

public bool IsValidatable => _settings.IsValidatable;
public bool SkipToString => _settings.SkipToString;
public bool SkipSwitchMethods => _settings.SkipSwitchMethods;
public bool SkipMapMethods => _settings.SkipMapMethods;
public bool? SkipSwitchMethods => _settings.SkipSwitchMethods;
public bool? SkipMapMethods => _settings.SkipMapMethods;
public bool HasStructLayoutAttribute => _attributeInfo.HasStructLayoutAttribute;
public IReadOnlyList<DesiredFactory> DesiredFactories => _attributeInfo.DesiredFactories;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,17 @@ public override int GetHashCode()
if (!_state.Settings.SkipToString)
GenerateToString();

if (!_state.Settings.SkipSwitchMethods)
var hasSaneNumberOfItems = _state.ItemNames.Count < 1000;

if (!_state.Settings.SkipSwitchMethods.GetValueOrDefault() && hasSaneNumberOfItems)
{
GenerateSwitchForAction(false);
GenerateSwitchForAction(true);
GenerateSwitchForFunc(false);
GenerateSwitchForFunc(true);
}

if (!_state.Settings.SkipMapMethods)
if (!_state.Settings.SkipMapMethods.GetValueOrDefault() && hasSaneNumberOfItems)
GenerateMap();

GenerateGetLookup();
Expand Down

0 comments on commit e5ca209

Please sign in to comment.