Skip to content

Commit

Permalink
Merge pull request #37 from ssttgg/top-level-stmts
Browse files Browse the repository at this point in the history
Top level statement support
  • Loading branch information
diegofrata authored Dec 18, 2022
2 parents 431e8f6 + 3fc0289 commit cf185f8
Show file tree
Hide file tree
Showing 26 changed files with 944 additions and 303 deletions.
4 changes: 2 additions & 2 deletions Generator.Equals.SnapshotTests/GeneratedSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static IEnumerable<object[]> FindSampleFiles([CallerFilePath] string? path = nul

public static IEnumerable<object[]> SampleFiles => FindSampleFiles();

async Task VerifyGeneratedSource(string directory, string fileName, string source,
public static async Task VerifyGeneratedSource(string directory, string fileName, string source, OutputKind outputKind = OutputKind.DynamicallyLinkedLibrary,
CancellationToken ct = default)
{
var referenceAssemblies = ReferenceAssemblies.Net.Net60;
Expand All @@ -42,7 +42,7 @@ async Task VerifyGeneratedSource(string directory, string fileName, string sourc
},
references: references
.Add(MetadataReference.CreateFromFile(typeof(CustomEqualityAttribute).Assembly.Location)),
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, nullableContextOptions: NullableContextOptions.Enable));
options: new CSharpCompilationOptions(outputKind, nullableContextOptions: NullableContextOptions.Enable));

var driver = CSharpGeneratorDriver
.Create(new EqualsGenerator())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//HintName: Animal.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

partial record Animal
{
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public virtual bool Equals(global::Animal? other)
{
return
!ReferenceEquals(other, null) && EqualityContract == other.EqualityContract
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(this.EqualityContract);
hashCode.Add(
this.Name!,
global::System.Collections.Generic.EqualityComparer<global::System.String>.Default);
hashCode.Add(
this.Age!,
global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//HintName: ClassSample.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

partial class ClassSample : global::System.IEquatable<ClassSample>
{
/// <summary>
/// Indicates whether the object on the left is equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator ==(
global::ClassSample? left,
global::ClassSample? right) =>
global::System.Collections.Generic.EqualityComparer<global::ClassSample?>.Default
.Equals(left, right);

/// <summary>
/// Indicates whether the object on the left is not equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are not equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator !=(global::ClassSample? left, global::ClassSample? right) =>
!(left == right);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj) =>
Equals(obj as global::ClassSample);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::ClassSample? other)
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(this.GetType());
hashCode.Add(
this.Name!,
global::System.Collections.Generic.EqualityComparer<global::System.String>.Default);
hashCode.Add(
this.Age!,
global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//HintName: Person.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

partial class Person : global::System.IEquatable<Person>
{
/// <summary>
/// Indicates whether the object on the left is equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator ==(
global::Person? left,
global::Person? right) =>
global::System.Collections.Generic.EqualityComparer<global::Person?>.Default
.Equals(left, right);

/// <summary>
/// Indicates whether the object on the left is not equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are not equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator !=(global::Person? left, global::Person? right) =>
!(left == right);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj) =>
Equals(obj as global::Person);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::Person? other)
{
return
!ReferenceEquals(other, null) && this.GetType() == other.GetType()
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(this.GetType());
hashCode.Add(
this.Name!,
global::System.Collections.Generic.EqualityComparer<global::System.String>.Default);
hashCode.Add(
this.Age!,
global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//HintName: RecordSample.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

partial record RecordSample
{
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public virtual bool Equals(global::RecordSample? other)
{
return
!ReferenceEquals(other, null) && EqualityContract == other.EqualityContract
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(this.EqualityContract);
hashCode.Add(
this.Name!,
global::System.Collections.Generic.EqualityComparer<global::System.String>.Default);
hashCode.Add(
this.Age!,
global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//HintName: RecordStructSample.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

partial record struct RecordStructSample
{
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::RecordStructSample other)
{
return true
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(
this.Name!,
global::System.Collections.Generic.EqualityComparer<global::System.String>.Default);
hashCode.Add(
this.Age!,
global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//HintName: StructSample.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

partial struct StructSample : global::System.IEquatable<StructSample>
{
/// <summary>
/// Indicates whether the object on the left is equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator ==(
global::StructSample left,
global::StructSample right) =>
global::System.Collections.Generic.EqualityComparer<global::StructSample>.Default
.Equals(left, right);

/// <summary>
/// Indicates whether the object on the left is not equal to the object on the right.
/// </summary>
/// <param name="left">The left object</param>
/// <param name="right">The right object</param>
/// <returns>true if the objects are not equal; otherwise, false.</returns>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public static bool operator !=(global::StructSample left, global::StructSample right) =>
!(left == right);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override bool Equals(object? obj) =>
obj is global::StructSample o && Equals(o);

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public bool Equals(global::StructSample other)
{
return true
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(
this.Name!,
global::System.Collections.Generic.EqualityComparer<global::System.String>.Default);
hashCode.Add(
this.Age!,
global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//HintName: Animal.Generator.Equals.g.cs

#nullable enable
#pragma warning disable CS0612,CS0618

partial record Animal
{
/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public virtual bool Equals(global::Animal? other)
{
return
!ReferenceEquals(other, null) && EqualityContract == other.EqualityContract
&& global::System.Collections.Generic.EqualityComparer<global::System.String>.Default.Equals(this.Name!, other.Name!)
&& global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default.Equals(this.Age!, other.Age!)
;
}

/// <inheritdoc/>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Generator.Equals", "1.0.0.0")]
public override int GetHashCode()
{
var hashCode = new global::System.HashCode();

hashCode.Add(this.EqualityContract);
hashCode.Add(
this.Name!,
global::System.Collections.Generic.EqualityComparer<global::System.String>.Default);
hashCode.Add(
this.Age!,
global::System.Collections.Generic.EqualityComparer<global::System.Int32>.Default);

return hashCode.ToHashCode();
}
}
Loading

0 comments on commit cf185f8

Please sign in to comment.