Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
namespace CodeGeneration_Attributes
{
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class CollectionValueEqualityAttribute : Attribute
public class CollectionValueEqualityAttribute : Attribute
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
namespace CodeGeneration_Attributes
{
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class GenerateEqualsAttribute : Attribute
public class GenerateEqualsAttribute : Attribute
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
namespace CodeGeneration_Attributes
{
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class GenerateGetHashCodeAttribute : Attribute
public class GenerateGetHashCodeAttribute : Attribute
{ }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
namespace CodeGeneration_Attributes
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false)]
public sealed class IgnoreEqualityAttribute : Attribute
public class IgnoreEqualityAttribute : Attribute
{ }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
20 changes: 10 additions & 10 deletions code generation/OpenLibraryNET.SourceGenerators/EqualsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ private string GetContents(INamedTypeSymbol symbol, ISymbol iEnumerableSymbol, I
{
StringBuilder sb = new StringBuilder();

sb.Append("///<summary>\n///Determines whether the specified object is equal to the current object.\n///Compares all fields by value; IEnumerables are compared by comparing the elements pairwise.\n///</summary>\n///<param name=\"other\">The object to compare with the current object.</param>\n///<returns>true if the specified object is equal to the current object; otherwise, false.</returns>\n");
sb.Append("///<summary>\r\n///Determines whether the specified object is equal to the current object.\r\n///Compares all fields by value; IEnumerables are compared by comparing the elements pairwise.\r\n///</summary>\r\n///<param name=\"other\">The object to compare with the current object.</param>\r\n///<returns>true if the specified object is equal to the current object; otherwise, false.</returns>\r\n");
if (symbol.TypeKind == TypeKind.Struct)
{
sb.Append($"[System.CodeDom.Compiler.GeneratedCode(\"{Utility.ToolName}\", \"{Utility.ToolVersion}\")]\npublic bool Equals({symbol.Name} other)\n{{");
sb.Append($"[System.CodeDom.Compiler.GeneratedCode(\"{Utility.ToolName}\", \"{Utility.ToolVersion}\")]\r\npublic bool Equals({symbol.Name} other)\r\n{{");
}
else
{
sb.Append($"[System.CodeDom.Compiler.GeneratedCode(\"{Utility.ToolName}\", \"{Utility.ToolVersion}\")]\npublic bool Equals({symbol.Name} other)\n{{");
sb.Append($"[System.CodeDom.Compiler.GeneratedCode(\"{Utility.ToolName}\", \"{Utility.ToolVersion}\")]\r\npublic virtual bool Equals({symbol.Name} other)\r\n{{");
}

List<IFieldSymbol> members = symbol.GetMembers().OfType<IFieldSymbol>().ToList();
Expand All @@ -91,11 +91,11 @@ private string GetContents(INamedTypeSymbol symbol, ISymbol iEnumerableSymbol, I
{
if (symbol.TypeKind == TypeKind.Struct)
{
sb.Append($"\n\treturn true");
sb.Append($"\r\n\treturn true");
}
else
{
sb.Append($"\n\treturn other != null");
sb.Append($"\r\n\treturn other != null");
}
}

Expand All @@ -113,11 +113,11 @@ private string GetContents(INamedTypeSymbol symbol, ISymbol iEnumerableSymbol, I

if (symbol.TypeKind == TypeKind.Struct)
{
sb.Append($"\n\treturn");
sb.Append($"\r\n\treturn");
}
else
{
sb.Append($"\n\treturn other != null &&");
sb.Append($"\r\n\treturn other != null &&");
}
}
else
Expand All @@ -128,15 +128,15 @@ private string GetContents(INamedTypeSymbol symbol, ISymbol iEnumerableSymbol, I
if (!SymbolEqualityComparer.Default.Equals(members[i].Type, stringSymbol)
&& members[i].Type.AllInterfaces.Any(sym => SymbolEqualityComparer.Default.Equals(sym, iEnumerableSymbol)))
{
sb.Append($"\n\t(({assoc.Name} == null && other.{assoc.Name} == null) || ({assoc.Name} != null && other.{assoc.Name} != null && {assoc.Name}.SequenceEqual(other.{assoc.Name})))");
sb.Append($"\r\n\t(({assoc.Name} == null && other.{assoc.Name} == null) || ({assoc.Name} != null && other.{assoc.Name} != null && {assoc.Name}.SequenceEqual(other.{assoc.Name})))");
}
else
{
sb.Append($"\n\t{assoc.Name} == other.{assoc.Name}");
sb.Append($"\r\n\t{assoc.Name} == other.{assoc.Name}");
}
}

sb.Append(";\n}");
sb.Append(";\r\n}");


// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ private string GetContents(GeneratorExecutionContext context, INamedTypeSymbol s
{
StringBuilder sb = new StringBuilder();

sb.Append("///<summary>\n///Serves as the default hash function.\n///IEnumerables are hashed element-wise.\n///</summary>\n///<returns>A hash code for the current object.</returns>\n");
sb.Append($"[System.CodeDom.Compiler.GeneratedCode(\"{Utility.ToolName}\", \"{Utility.ToolVersion}\")]\npublic override int GetHashCode()\n{{\n\tHashCode hash = new HashCode();");
sb.Append("///<summary>\r\n///Serves as the default hash function.\r\n///IEnumerables are hashed element-wise.\r\n///</summary>\r\n///<returns>A hash code for the current object.</returns>\r\n");
sb.Append($"[System.CodeDom.Compiler.GeneratedCode(\"{Utility.ToolName}\", \"{Utility.ToolVersion}\")]\r\npublic override int GetHashCode()\r\n{{\r\n\tHashCode hash = new HashCode();");

ISymbol iEnumerableSymbol = context.Compilation.GetSpecialType(SpecialType.System_Collections_IEnumerable);
ISymbol stringSymbol = context.Compilation.GetSpecialType(SpecialType.System_String);
Expand All @@ -91,15 +91,15 @@ private string GetContents(GeneratorExecutionContext context, INamedTypeSymbol s
if (!SymbolEqualityComparer.Default.Equals(members[i].Type, stringSymbol)
&& members[i].Type.AllInterfaces.Any(sym => SymbolEqualityComparer.Default.Equals(sym, iEnumerableSymbol)))
{
sb.Append($"\n\tif ({assoc.Name} != null)\n\t{{\n\t\tforeach (var element in {assoc.Name})\n\t\t{{\n\t\t\thash.Add(element);\n\t\t}}\n\t}}\n\telse\n\t{{\n\t\thash.Add({assoc.Name});\n\t}}");
sb.Append($"\r\n\tif ({assoc.Name} != null)\r\n\t{{\r\n\t\tforeach (var element in {assoc.Name})\r\n\t\t{{\r\n\t\t\thash.Add(element);\r\n\t\t}}\r\n\t}}\r\n\telse\r\n\t{{\r\n\t\thash.Add({assoc.Name});\r\n\t}}");
}
else
{
sb.Append($"\n\thash.Add(this.{assoc.Name});");
sb.Append($"\r\n\thash.Add(this.{assoc.Name});");
}
}

sb.Append("\n\treturn hash.ToHashCode();\n}");
sb.Append("\r\n\treturn hash.ToHashCode();\r\n}");
return sb.ToString();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Expand Down
11 changes: 5 additions & 6 deletions code generation/OpenLibraryNET.SourceGenerators/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static string BuildSource(INamedTypeSymbol symbol, string contents)

if (symbol.ContainingNamespace != null)
{
sb.AppendLine($"namespace {symbol.ContainingNamespace.ToDisplayString()}\n{{");
sb.AppendLine($"namespace {symbol.ContainingNamespace.ToDisplayString()}\r\n{{");
indent++;
}

Expand All @@ -94,19 +94,19 @@ public static string BuildSource(INamedTypeSymbol symbol, string contents)

foreach (var currentSymbol in containingTypes)
{
sb.AppendIndented($"\n{GetDeclaration(currentSymbol)}\n{{", indent);
sb.AppendIndented($"\r\n{GetDeclaration(currentSymbol)}\r\n{{", indent);
indent++;
}
}

sb.AppendIndented($"\n{GetDeclaration(symbol)}\n{{", indent);
sb.AppendIndented($"\r\n{GetDeclaration(symbol)}\r\n{{", indent);
indent++;
sb.AppendIndented(contents, indent);
indent--;

while (indent >= 0)
{
sb.AppendIndented("\n}", indent);
sb.AppendIndented("\r\n}", indent);
indent--;
}

Expand All @@ -115,8 +115,7 @@ public static string BuildSource(INamedTypeSymbol symbol, string contents)

public static StringBuilder AppendIndented(this StringBuilder sb, string textBlock, int indentationLevel)
{
char[] chars = new char[1] { '\n' };
foreach (var line in textBlock.TrimEnd().Split(chars, StringSplitOptions.RemoveEmptyEntries))
foreach (var line in textBlock.TrimEnd().Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None))
if (!string.IsNullOrWhiteSpace(line))
sb.AppendLine($"{string.Concat(Enumerable.Repeat("\t", indentationLevel))}{line}");
return sb;
Expand Down
2 changes: 1 addition & 1 deletion src/OLAuthor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OpenLibraryNET
/// Composite storage of various data related to an author.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLAuthor
public partial record OLAuthor
{
/// <summary>
/// The ID of the author.
Expand Down
2 changes: 1 addition & 1 deletion src/OLData/OLAuthorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenLibraryNET.Data
/// Holds data about an author.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLAuthorData : OLContainer
public partial record OLAuthorData : OLContainer
{
/// <summary>
/// The ID of the author.
Expand Down
2 changes: 1 addition & 1 deletion src/OLData/OLBookViewAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OpenLibraryNET.Data
/// Holds data about a book's ViewAPI.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLBookViewAPI : OLContainer
public partial record OLBookViewAPI : OLContainer
{
/// <summary>
/// The book's bibkey.
Expand Down
2 changes: 1 addition & 1 deletion src/OLData/OLBookshelvesData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OpenLibraryNET.Data
/// Holds data about a <see cref="OLWorkData"/>'s bookshelves.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLBookshelvesData : OLContainer
public partial record OLBookshelvesData : OLContainer
{
/// <summary>
/// The amount of accounts that marked the corresponding work as "Want to read".
Expand Down
4 changes: 2 additions & 2 deletions src/OLData/OLEditionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenLibraryNET.Data
/// Holds data about an edition.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLEditionData : OLContainer
public partial record OLEditionData : OLContainer
{
/// <summary>
/// The edition's ID.
Expand Down Expand Up @@ -138,7 +138,7 @@ public IReadOnlyList<string> Publishers
/// Holds the various identifiers of an edition.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLEditionIdentifiers : OLContainer
public partial record OLEditionIdentifiers : OLContainer
{
/// <summary>
/// The Goodreads identifiers of the corresponding edition.
Expand Down
2 changes: 1 addition & 1 deletion src/OLData/OLListData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OpenLibraryNET.Data
/// Holds data about a user-created list.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLListData : OLContainer
public partial record OLListData : OLContainer
{
/// <summary>
/// The list's ID.
Expand Down
4 changes: 2 additions & 2 deletions src/OLData/OLMyBooksData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OpenLibraryNET.Data
/// Holds data about a user's reading log.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLMyBooksData : OLContainer
public partial record OLMyBooksData : OLContainer
{
/// <summary>
/// Pagination data about the reading log.<br/>
Expand All @@ -34,7 +34,7 @@ public IReadOnlyList<OLReadingLogEntry> ReadingLogEntries
/// Holds data about an entry in a given reading log.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLReadingLogEntry : OLContainer
public partial record OLReadingLogEntry : OLContainer
{
/// <summary>
/// The corresponding <see cref="OLWorkData"/>.
Expand Down
6 changes: 3 additions & 3 deletions src/OLData/OLPartnerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenLibraryNET.Data
/// Holds data about online-readable or borrowable books, along with corresponding <see cref="OLEditionData"/> and <see cref="OLBookViewAPI"/> entries.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLPartnerData : OLContainer
public partial record OLPartnerData : OLContainer
{
/// <summary>
/// The corresponding <see cref="OLEditionData"/>.
Expand Down Expand Up @@ -39,7 +39,7 @@ public IReadOnlyList<Item> Items
/// Holds data about an online-readable book.
/// </summary>
[CollectionValueEquality]
public sealed partial record Item : OLContainer
public partial record Item : OLContainer
{
/// <summary>
/// The type of match. Either 'exact' or 'similar'.
Expand Down Expand Up @@ -81,7 +81,7 @@ public sealed partial record Item : OLContainer
/// Holds URLs to the cover of the corresponding <see cref="Item"/>.
/// </summary>
[CollectionValueEquality]
public sealed partial record CoverURL : OLContainer
public partial record CoverURL : OLContainer
{
/// <summary>
/// Link to the cover in small resolution.
Expand Down
2 changes: 1 addition & 1 deletion src/OLData/OLRatingsData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OpenLibraryNET.Data
/// Holds data about a <see cref="OLWorkData"/>'s ratings.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLRatingsData : OLContainer
public partial record OLRatingsData : OLContainer
{
/// <summary>
/// The corresponding work's average rating. Null if there are no ratings.
Expand Down
4 changes: 2 additions & 2 deletions src/OLData/OLRecentChangesData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenLibraryNET.Data
/// Holds data about recent changes made to OpenLibrary's data.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLRecentChangesData : OLContainer
public partial record OLRecentChangesData : OLContainer
{
/// <summary>
/// The ID of the change made.
Expand Down Expand Up @@ -55,7 +55,7 @@ public IReadOnlyList<OLChangeData> Changes
/// Holds data about the data entries that were changed.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLChangeData : OLContainer
public partial record OLChangeData : OLContainer
{
/// <summary>
/// The key of the object that was changed.
Expand Down
2 changes: 1 addition & 1 deletion src/OLData/OLSeedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenLibraryNET.OLData
/// Holds data about a list seed.
/// </summary>
[CollectionValueEquality]
public sealed partial record class OLSeedData : OLContainer
public partial record class OLSeedData : OLContainer
{
/// <summary>
/// The ID of this seed.
Expand Down
2 changes: 1 addition & 1 deletion src/OLData/OLSubjectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenLibraryNET.Data
/// Holds data about a subject.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLSubjectData : OLContainer
public partial record OLSubjectData : OLContainer
{
/// <summary>
/// The name of this subject.
Expand Down
2 changes: 1 addition & 1 deletion src/OLData/OLWorkData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenLibraryNET.Data
/// Holds data about a work.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLWorkData : OLContainer
public partial record OLWorkData : OLContainer
{
/// <summary>
/// The ID of the work.
Expand Down
2 changes: 1 addition & 1 deletion src/OLEdition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OpenLibraryNET
/// Composite storage of various data related to an edition.
/// </summary>
[CollectionValueEquality]
public sealed partial record OLEdition
public partial record OLEdition
{
/// <summary>
/// The ID of the edition.
Expand Down
Loading