Skip to content

Commit

Permalink
Move to C# 12 and rework API
Browse files Browse the repository at this point in the history
  • Loading branch information
sailro committed Nov 23, 2023
1 parent 8a7d697 commit ce64225
Show file tree
Hide file tree
Showing 92 changed files with 528 additions and 791 deletions.
2 changes: 1 addition & 1 deletion Dexer.Debug/Dexer.Debug.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
3 changes: 1 addition & 2 deletions Dexer.Debug/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -19,7 +19,6 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System;
using Dexer.Core;

namespace Dexer.Debug;
Expand Down
13 changes: 5 additions & 8 deletions Dexer.Tests/BaseCollectorTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -19,9 +19,6 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System;
using System.Collections.Generic;
using System.Linq;
using Dexer.Core;
using Dexer.IO.Collectors;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -31,15 +28,15 @@ namespace Dexer.Tests;
[TestClass]
public class BaseCollectorTest : BaseTest
{
internal void TestCollector<TC, T>(Func<Dex, List<T>> provider) where TC : BaseCollector<T>, new()
internal void TestCollector<TC, T>(Func<Dex, List<T>> provider) where TC : BaseCollector<T>, new() where T : notnull
{
foreach (var file in GetTestFiles())
{
TestCollector<TC, T>(provider, file);
}
}

internal TC TestCollector<TC, T>(Func<Dex, List<T>> provider, string file) where TC : BaseCollector<T>, new()
internal TC TestCollector<TC, T>(Func<Dex, List<T>> provider, string file) where TC : BaseCollector<T>, new() where T : notnull
{
TestContext.WriteLine("Testing {0}", file);
var dex = Dex.Read(file);
Expand All @@ -51,10 +48,10 @@ public class BaseCollectorTest : BaseTest
var destKeys = collector.Items.ToDictionary(kv => kv.Key);

foreach (var key in sourceKeys.Keys)
Assert.IsTrue(collector.Items.ContainsKey(key) || (key.ToString() == "this"), "Item '{0}' not collected", key);
Assert.IsTrue(collector.Items.ContainsKey(key) || key.ToString() == "this", "Item '{0}' not collected", key);

foreach (var key in destKeys.Keys)
Assert.IsTrue(sourceKeys.ContainsKey(key) || (key.ToString() == "this"), "Item '{0}' is 'over' collected", key);
Assert.IsTrue(sourceKeys.ContainsKey(key) || key.ToString() == "this", "Item '{0}' is 'over' collected", key);

return collector;
}
Expand Down
14 changes: 4 additions & 10 deletions Dexer.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -19,8 +19,6 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -39,17 +37,13 @@ public string[] GetTestFiles()
return Directory.GetFiles(basePath, "*.dex");
}

public TestContext TestContext
{
get;
set;
}
public required TestContext TestContext { get; set; }

public void DumpList<T>(string filename, List<T> list)
public static void DumpList<T>(string filename, List<T> list)
{
var output = new StringBuilder();
foreach (var item in list)
output.AppendLine(item.ToString());
output.AppendLine(item?.ToString());

File.WriteAllText(filename, output.ToString());
}
Expand Down
2 changes: 1 addition & 1 deletion Dexer.Tests/CollectorTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
10 changes: 5 additions & 5 deletions Dexer.Tests/Dexer.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" Version="1.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 2 additions & 5 deletions Dexer.Tests/InstructionTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -19,8 +19,6 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System;
using System.Collections.Generic;
using Dexer.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Dexer.Instructions;
Expand Down Expand Up @@ -51,8 +49,7 @@ public void TestUpdateInstructionOffsets()
var offsets = new List<int>();
foreach (var ins in method.Body.Instructions)
{
if (!coverage.ContainsKey(ins.OpCode))
coverage.Add(ins.OpCode, 0);
coverage.TryAdd(ins.OpCode, 0);
offsets.Add(ins.Offset);
coverage[ins.OpCode]++;
}
Expand Down
8 changes: 2 additions & 6 deletions Dexer.Tests/NumericalTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -20,11 +20,7 @@
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using Dexer.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Dexer.Tests;

Expand All @@ -37,7 +33,7 @@ public void TestNumber<T>(Func<BinaryReader, T> readProvider, Action<BinaryWrite
var reader = new BinaryReader(stream);
var writer = new BinaryWriter(stream);

foreach (var expected in values.Select(item => (T)Convert.ChangeType(item, typeof(T))))
foreach (var expected in values.Select(item => (T)Convert.ChangeType(item, typeof(T))!))
{
TestContext.WriteLine("{0}, {0:x}", expected);

Expand Down
5 changes: 1 addition & 4 deletions Dexer.Tests/RoundtripTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -19,9 +19,6 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System.Collections.Generic;
using System.IO;
using System.Linq;
using Dexer.Core;
using Dexer.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down
6 changes: 2 additions & 4 deletions Dexer.Tests/SortTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -19,8 +19,6 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System;
using System.Collections.Generic;
using Dexer.Core;
using Dexer.Extensions;
using Dexer.IO.Collectors;
Expand All @@ -32,7 +30,7 @@ namespace Dexer.Tests;
[TestClass]
public class SortTest : BaseCollectorTest
{
public void TestGlobalSort<T>(Func<Dex, List<T>> provider, IComparer<T> comparer)
public void TestGlobalSort<T>(Func<Dex, List<T>> provider, IComparer<T> comparer) where T : notnull
{
foreach (var file in GetTestFiles())
{
Expand Down
4 changes: 1 addition & 3 deletions Dexer/Core/AccessFlags.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -19,8 +19,6 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System;

namespace Dexer.Core;

[Flags]
Expand Down
20 changes: 6 additions & 14 deletions Dexer/Core/Annotation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -19,25 +19,17 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System.Collections.Generic;
using System.Text;
using Dexer.Metadata;
using System;
using System.Linq;

namespace Dexer.Core;

public class Annotation : IEquatable<Annotation>
public class Annotation(ClassReference type) : IEquatable<Annotation>
{
public ClassReference Type { get; set; }
public List<AnnotationArgument> Arguments { get; set; }
public ClassReference Type { get; } = type;
public List<AnnotationArgument> Arguments { get; } = [];
public AnnotationVisibility Visibility { get; set; }

public Annotation()
{
Arguments = new List<AnnotationArgument>();
}

public override string ToString()
{
var builder = new StringBuilder();
Expand All @@ -55,7 +47,7 @@ public override string ToString()
return builder.ToString();
}

public bool Equals(Annotation other)
public bool Equals(Annotation? other)
{
if (other == null)
return false;
Expand All @@ -66,7 +58,7 @@ public bool Equals(Annotation other)
return !Arguments.Where((t, i) => !t.Equals(other.Arguments[i])).Any();
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is Annotation annotation && Equals(annotation);
}
Expand Down
12 changes: 5 additions & 7 deletions Dexer/Core/AnnotationArgument.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand All @@ -19,17 +19,15 @@
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

using System.Linq;
using Dexer.Metadata;
using System.Text;
using System;

namespace Dexer.Core;

public class AnnotationArgument : IEquatable<AnnotationArgument>
public class AnnotationArgument(string name, object? value) : IEquatable<AnnotationArgument>
{
public string Name { get; set; }
public object Value { get; set; }
public string Name { get; } = name;
public object? Value { get; } = value;

public override string ToString()
{
Expand All @@ -47,7 +45,7 @@ public bool Equals(AnnotationArgument other)

return Name.Equals(other.Name)
&& ValueFormat.GetFormat(Value).Equals(ValueFormat.GetFormat(other.Value))
&& (ValueFormat.GetFormat(Value) == ValueFormats.Array && ArrayEquals(Value as Array, other.Value as Array) || Equals(Value, other.Value));
&& (ValueFormat.GetFormat(Value) == ValueFormats.Array && ArrayEquals((Array)Value!, (Array)other.Value!) || Equals(Value, other.Value));
}

internal static bool ArrayEquals(Array array1, Array array2)
Expand Down
2 changes: 1 addition & 1 deletion Dexer/Core/AnnotationVisibility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
5 changes: 3 additions & 2 deletions Dexer/Core/ArrayType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Dexer Copyright (c) 2010-2022 Sebastien Lebreton
/* Dexer Copyright (c) 2010-2023 Sebastien Lebreton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down Expand Up @@ -27,8 +27,9 @@ public class ArrayType : CompositeType
{
public TypeReference ElementType { get; set; }

public ArrayType()
public ArrayType(TypeReference elementType)
{
ElementType = elementType;
TypeDescriptor = TypeDescriptors.Array;
}

Expand Down

0 comments on commit ce64225

Please sign in to comment.