Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #128: Roll back to net462 by replacing tuples with anonymous types #129

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading