Skip to content

Commit

Permalink
Merge pull request #129 from ahmetsait/master
Browse files Browse the repository at this point in the history
Fix #128: Roll back to net462 by replacing tuples with anonymous types
  • Loading branch information
desjarlais authored Jul 10, 2024
2 parents 3d1d74a + 92caed8 commit 1537659
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Scintilla.NET/FlagsConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
ulong bits = 0;
List<Enum> enums = [];
var items = Enum.GetValues(enumType).Cast<Enum>()
.Select(e => (@enum: e, bits: Convert.ToUInt64(e), bitCount: Helpers.PopCount(Convert.ToUInt64(e))))
.Select(e => new { @enum = e, bits = Convert.ToUInt64(e), bitCount = Helpers.PopCount(Convert.ToUInt64(e))})
.Where(e => e.bits != 0 && e.bitCount > 0)
.ToList();
int maxIterations = items.Count;
for (int i = 0; i < maxIterations && bits != valueBits && items.Count > 0; i++)
{
int maxIndex = items
.Select(e => (contrib: Helpers.PopCount(e.bits & valueBits & ~bits), item: e))
.Select(e => new { contrib = Helpers.PopCount(e.bits & valueBits & ~bits), item = e})
.MaxIndex(
(x, y) => // Select one that:
(x.contrib != y.contrib) ? (x.contrib - y.contrib) : // Contributes most bits
(x.item.bitCount != y.item.bitCount) ? (y.item.bitCount - x.item.bitCount) : // Has least amount of bits set
(x.item.bits < y.item.bits) ? -1 : (x.item.bits > y.item.bits ? 1 : 0) // With the highest integer value
);

(Enum @enum, ulong bits, byte bitCount) item = items[maxIndex];
var item = items[maxIndex];

if ((valueBits & item.bits) == item.bits && (bits & item.bits) != item.bits)
{
Expand Down
2 changes: 1 addition & 1 deletion Scintilla.NET/Scintilla.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProjectGuid>{22AE2386-60F1-476E-9303-61CDB0AAC4CF}</ProjectGuid>
<TargetFrameworks>net47;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net462;net6.0-windows</TargetFrameworks>
<NeutralLanguage>en-US</NeutralLanguage>
<Description>Source Editing Component based on Scintilla 5 series.</Description>
<Copyright>Copyright (c) Jacob Slusser 2018, VPKSoft, cyber960 2022, desjarlais 2023.</Copyright>
Expand Down

0 comments on commit 1537659

Please sign in to comment.