-
Notifications
You must be signed in to change notification settings - Fork 2
Address some stuff reported/suggested by code analyzers #167
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,35 @@ | ||
namespace LeanCode.Contracts.Admin; | ||
|
||
public abstract class AdminQuery<TResult> : IQuery<AdminQueryResult<TResult>> | ||
{ | ||
/// <remarks>0-based</remarks> | ||
public int Page { get; set; } | ||
public int PageSize { get; set; } | ||
|
||
public bool? SortDescending { get; set; } | ||
public string? SortBy { get; set; } | ||
} | ||
|
||
public class AdminQueryResult<TResult> | ||
{ | ||
public long Total { get; set; } | ||
public List<TResult> Items { get; set; } | ||
} | ||
|
||
public class AdminFilterRange<T> | ||
{ | ||
public T? From { get; set; } | ||
public T? To { get; set; } | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | ||
public class AdminFilterFor : Attribute | ||
{ | ||
public AdminFilterFor(string name) { } | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] | ||
public class AdminLabel : Attribute | ||
{ | ||
public AdminLabel(string label) { } | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | ||
public class AdminColumn : Attribute | ||
{ | ||
public AdminColumn(string? name) { } | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | ||
public class AdminSortable : Attribute | ||
{ | ||
public AdminSortable() { } | ||
} | ||
namespace LeanCode.Contracts.Admin; | ||
|
||
public abstract class AdminQuery<TResult> : IQuery<AdminQueryResult<TResult>> | ||
{ | ||
/// <remarks>0-based</remarks> | ||
public int Page { get; set; } | ||
public int PageSize { get; set; } | ||
|
||
public bool? SortDescending { get; set; } | ||
public string? SortBy { get; set; } | ||
} | ||
|
||
public class AdminQueryResult<TResult> | ||
{ | ||
public long Total { get; set; } | ||
public List<TResult> Items { get; set; } | ||
} | ||
|
||
public class AdminFilterRange<T> | ||
{ | ||
public T? From { get; set; } | ||
public T? To { get; set; } | ||
} | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | ||
public class AdminFilterForAttribute(string name) : Attribute; | ||
|
||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] | ||
public class AdminLabelAttribute(string label) : Attribute; | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | ||
public class AdminColumnAttribute(string? name) : Attribute; | ||
|
||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] | ||
public class AdminSortableAttribute : Attribute; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace LeanCode.Contracts; | ||
|
||
[System.Text.Json.Serialization.JsonConverter(typeof(Converters.BinaryJsonConverter))] | ||
public record struct Binary : IEquatable<Binary> | ||
public readonly record struct Binary : IEquatable<Binary> | ||
{ | ||
private readonly byte[]? data; | ||
|
||
public byte[] Data => data ?? Array.Empty<byte>(); | ||
public readonly byte[] Data => data ?? []; | ||
|
||
public Binary(byte[] data) | ||
public Binary(byte[]? data) | ||
{ | ||
ArgumentNullException.ThrowIfNull(data); | ||
|
||
this.data = data; | ||
} | ||
|
||
public bool Equals(Binary other) | ||
{ | ||
var otherData = other.Data; | ||
return Data.Length == otherData.Length && Data.SequenceEqual(otherData); | ||
} | ||
public bool Equals(Binary other) => MemoryExtensions.SequenceEqual(Data, other.Data); | ||
|
||
public override int GetHashCode() => Data.Length; | ||
public override int GetHashCode() => | ||
data switch | ||
{ | ||
{ LongLength: > 4 } d => HashCode.Combine( | ||
BitConverter.ToInt32(d.AsSpan(0..4)), | ||
BitConverter.ToInt32(d.AsSpan(^4..^0)) | ||
), | ||
Comment on lines
+22
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you let me know how that works, especially the second call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each call reinterprets 4 bytes of the array as int32, the first one looking at first 4 bytes and the second looking at last 4 bytes. It's not by any means smart but it's as much input data as I can get in fixed time as reasonably possible. |
||
{ LongLength: 4 } d => BitConverter.ToInt32(d), | ||
{ LongLength: 2 or 3 } d => BitConverter.ToInt16(d), | ||
{ LongLength: 1 } d => d[0], | ||
_ => 0, | ||
}; | ||
|
||
#if NET7_0_OR_GREATER | ||
[return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull(nameof(binary))] | ||
#else | ||
[return: System.Diagnostics.CodeAnalysis.NotNullIfNotNull("binary")] | ||
#endif | ||
[return: NotNullIfNotNull(nameof(binary))] | ||
public static implicit operator byte[]?(Binary? binary) => binary?.Data; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
namespace LeanCode.Contracts; | ||
|
||
[System.Diagnostics.CodeAnalysis.SuppressMessage("?", "CA1040", Justification = "Marker interface.")] | ||
public interface ICommand { } | ||
public interface ICommand; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
namespace LeanCode.Contracts; | ||
|
||
[System.Diagnostics.CodeAnalysis.SuppressMessage("?", "CA1040", Justification = "Marker interface.")] | ||
public interface IProduceNotification<TNotification> | ||
where TNotification : notnull { } | ||
where TNotification : notnull; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
namespace LeanCode.Contracts; | ||
|
||
[System.Diagnostics.CodeAnalysis.SuppressMessage("?", "CA1040", Justification = "Marker interface.")] | ||
public interface ITopic { } | ||
public interface ITopic; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace LeanCode.Contracts.Security; | ||
|
||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false, Inherited = true)] | ||
public sealed class AllowUnauthorizedAttribute : Attribute { } | ||
public sealed class AllowUnauthorizedAttribute : Attribute; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what happened in this file? Encoding change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed line endings from CRLF to LF.