chore: add csharpier to husky, format backend with csharpier
This commit is contained in:
parent
5fab66444f
commit
7f971e8549
73 changed files with 2098 additions and 1048 deletions
|
@ -41,19 +41,26 @@ public readonly struct Snowflake(ulong value) : IEquatable<Snowflake>
|
|||
public short Increment => (short)(Value & 0xFFF);
|
||||
|
||||
public static bool operator <(Snowflake arg1, Snowflake arg2) => arg1.Value < arg2.Value;
|
||||
|
||||
public static bool operator >(Snowflake arg1, Snowflake arg2) => arg1.Value > arg2.Value;
|
||||
|
||||
public static bool operator ==(Snowflake arg1, Snowflake arg2) => arg1.Value == arg2.Value;
|
||||
|
||||
public static bool operator !=(Snowflake arg1, Snowflake arg2) => arg1.Value != arg2.Value;
|
||||
|
||||
public static implicit operator ulong(Snowflake s) => s.Value;
|
||||
|
||||
public static implicit operator long(Snowflake s) => (long)s.Value;
|
||||
|
||||
public static implicit operator Snowflake(ulong n) => new(n);
|
||||
|
||||
public static implicit operator Snowflake(long n) => new((ulong)n);
|
||||
|
||||
public static bool TryParse(string input, [NotNullWhen(true)] out Snowflake? snowflake)
|
||||
{
|
||||
snowflake = null;
|
||||
if (!ulong.TryParse(input, out var res)) return false;
|
||||
if (!ulong.TryParse(input, out var res))
|
||||
return false;
|
||||
snowflake = new Snowflake(res);
|
||||
return true;
|
||||
}
|
||||
|
@ -66,27 +73,37 @@ public readonly struct Snowflake(ulong value) : IEquatable<Snowflake>
|
|||
}
|
||||
|
||||
public override int GetHashCode() => Value.GetHashCode();
|
||||
|
||||
public override string ToString() => Value.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// An Entity Framework ValueConverter for Snowflakes to longs.
|
||||
/// </summary>
|
||||
// ReSharper disable once ClassNeverInstantiated.Global
|
||||
public class ValueConverter() : ValueConverter<Snowflake, long>(
|
||||
convertToProviderExpression: x => x,
|
||||
convertFromProviderExpression: x => x
|
||||
);
|
||||
public class ValueConverter()
|
||||
: ValueConverter<Snowflake, long>(
|
||||
convertToProviderExpression: x => x,
|
||||
convertFromProviderExpression: x => x
|
||||
);
|
||||
|
||||
private class JsonConverter : JsonConverter<Snowflake>
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, Snowflake value, JsonSerializer serializer)
|
||||
public override void WriteJson(
|
||||
JsonWriter writer,
|
||||
Snowflake value,
|
||||
JsonSerializer serializer
|
||||
)
|
||||
{
|
||||
writer.WriteValue(value.Value.ToString());
|
||||
}
|
||||
|
||||
public override Snowflake ReadJson(JsonReader reader, Type objectType, Snowflake existingValue,
|
||||
public override Snowflake ReadJson(
|
||||
JsonReader reader,
|
||||
Type objectType,
|
||||
Snowflake existingValue,
|
||||
bool hasExistingValue,
|
||||
JsonSerializer serializer)
|
||||
JsonSerializer serializer
|
||||
)
|
||||
{
|
||||
return ulong.Parse((string)reader.Value!);
|
||||
}
|
||||
|
@ -97,12 +114,18 @@ public readonly struct Snowflake(ulong value) : IEquatable<Snowflake>
|
|||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) =>
|
||||
sourceType == typeof(string);
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen(true)] Type? destinationType) =>
|
||||
destinationType == typeof(Snowflake);
|
||||
public override bool CanConvertTo(
|
||||
ITypeDescriptorContext? context,
|
||||
[NotNullWhen(true)] Type? destinationType
|
||||
) => destinationType == typeof(Snowflake);
|
||||
|
||||
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
|
||||
public override object? ConvertFrom(
|
||||
ITypeDescriptorContext? context,
|
||||
CultureInfo? culture,
|
||||
object value
|
||||
)
|
||||
{
|
||||
return TryParse((string)value, out var snowflake) ? snowflake : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue