Skip to content

Commit

Permalink
#45 add method internal options
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Sep 9, 2024
1 parent cf41bee commit e4febc3
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 586 deletions.
66 changes: 21 additions & 45 deletions src/Injectio.Generators/EquatableArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,44 @@
namespace Injectio.Generators;

[ExcludeFromCodeCoverage]
public readonly struct EquatableArray<T> : IReadOnlyCollection<T>, IEquatable<EquatableArray<T>>
public readonly struct EquatableArray<T>(T[] array) : IEquatable<EquatableArray<T>>, IEnumerable<T>
where T : IEquatable<T>
{
public static readonly EquatableArray<T> Empty = new(Array.Empty<T>());
public T[] Array { get; } = array ?? [];

private readonly T[] _array;
public int Count => Array.Length;

public EquatableArray(T[] array)
{
_array = array;
}
public ReadOnlySpan<T> AsSpan() => Array.AsSpan();

public EquatableArray(IEnumerable<T>? array)
{
array ??= Enumerable.Empty<T>();
_array = array.ToArray();
}
public T[] AsArray() => Array;

public bool Equals(EquatableArray<T> array)
{
return AsSpan().SequenceEqual(array.AsSpan());
}

public override bool Equals(object obj)
{
return obj is EquatableArray<T> array && Equals(this, array);
}
public static bool operator ==(EquatableArray<T> left, EquatableArray<T> right) => left.Equals(right);

public static bool operator !=(EquatableArray<T> left, EquatableArray<T> right) => !left.Equals(right);

public bool Equals(EquatableArray<T> array) => Array.AsSpan().SequenceEqual(array.AsSpan());

public override bool Equals(object? obj) => obj is EquatableArray<T> array && Equals(this, array);

public override int GetHashCode()
{
if (_array is null)
if (Array is not T[] array)
return 0;

return HashCode.Seed.CombineAll(_array);
}
var hashCode = 16777619;

public ReadOnlySpan<T> AsSpan()
{
return _array.AsSpan();
}
for (int i = 0; i < array.Length; i++)
hashCode = unchecked((hashCode * -1521134295) + EqualityComparer<T>.Default.GetHashCode(array[i]));

IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
IEnumerable<T> array = _array ?? Array.Empty<T>();
return array.GetEnumerator();
return hashCode;
}

IEnumerator IEnumerable.GetEnumerator()
{
IEnumerable<T> array = _array ?? Array.Empty<T>();
return array.GetEnumerator();
}

public int Count => _array?.Length ?? 0;
IEnumerator<T> IEnumerable<T>.GetEnumerator() => (Array as IEnumerable<T>).GetEnumerator();

public static bool operator ==(EquatableArray<T> left, EquatableArray<T> right)
{
return left.Equals(right);
}
IEnumerator IEnumerable.GetEnumerator() => Array.GetEnumerator();

public static bool operator !=(EquatableArray<T> left, EquatableArray<T> right)
{
return !left.Equals(right);
}

public static implicit operator EquatableArray<T>(T[] array) => new(array);
}
241 changes: 0 additions & 241 deletions src/Injectio.Generators/HashCode.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Injectio.Generators/Injectio.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project>
<ItemGroup>
<CompilerVisibleProperty Include="InjectioName" />
<CompilerVisibleProperty Include="InjectioInternal" />
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions src/Injectio.Generators/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.ComponentModel;

#pragma warning disable IDE0130 // Namespace does not match folder structure
namespace System.Runtime.CompilerServices;
#pragma warning restore IDE0130 // Namespace does not match folder structure

[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit { }
6 changes: 6 additions & 0 deletions src/Injectio.Generators/MethodOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Injectio.Generators;

public record MethodOptions(
string? Name,
string? Internal
);
Loading

0 comments on commit e4febc3

Please sign in to comment.