Refactor models and add IHasId/IdBasedEqualityComparer

pull/278/head
Alexey Golub 5 years ago
parent 23512dae64
commit fc38afe6a0

@ -6,7 +6,7 @@ namespace DiscordChatExporter.Core.Models
{ {
// https://discordapp.com/developers/docs/resources/channel#attachment-object // https://discordapp.com/developers/docs/resources/channel#attachment-object
public partial class Attachment public partial class Attachment : IHasId
{ {
public string Id { get; } public string Id { get; }

@ -2,13 +2,13 @@
{ {
// https://discordapp.com/developers/docs/resources/channel#channel-object // https://discordapp.com/developers/docs/resources/channel#channel-object
public partial class Channel public partial class Channel : IHasId
{ {
public string Id { get; } public string Id { get; }
public string? ParentId { get; } public string? ParentId { get; }
public string? GuildId { get; } public string GuildId { get; }
public string Name { get; } public string Name { get; }
@ -16,7 +16,7 @@
public ChannelType Type { get; } public ChannelType Type { get; }
public Channel(string id, string? parentId, string? guildId, string name, string? topic, ChannelType type) public Channel(string id, string? parentId, string guildId, string name, string? topic, ChannelType type)
{ {
Id = id; Id = id;
ParentId = parentId; ParentId = parentId;
@ -32,6 +32,6 @@
public partial class Channel public partial class Channel
{ {
public static Channel CreateDeletedChannel(string id) => public static Channel CreateDeletedChannel(string id) =>
new Channel(id, null, null, "deleted-channel", null, ChannelType.GuildTextChat); new Channel(id, null, "unknown-guild", "deleted-channel", null, ChannelType.GuildTextChat);
} }
} }

@ -6,7 +6,7 @@ namespace DiscordChatExporter.Core.Models
{ {
// https://discordapp.com/developers/docs/resources/emoji#emoji-object // https://discordapp.com/developers/docs/resources/emoji#emoji-object
public partial class Emoji public partial class Emoji : IHasId
{ {
public string? Id { get; } public string? Id { get; }

@ -30,7 +30,6 @@ namespace DiscordChatExporter.Core.Models
{ {
get get
{ {
// Absolute value is used to deal with negative values
if (Math.Abs(PetaBytes) >= 1) if (Math.Abs(PetaBytes) >= 1)
return PetaByteSymbol; return PetaByteSymbol;
@ -54,7 +53,6 @@ namespace DiscordChatExporter.Core.Models
{ {
get get
{ {
// Absolute value is used to deal with negative values
if (Math.Abs(PetaBytes) >= 1) if (Math.Abs(PetaBytes) >= 1)
return PetaBytes; return PetaBytes;

@ -2,7 +2,7 @@
{ {
// https://discordapp.string.IsNullOrWhiteSpace(com/developers/docs/resources/guild#guild-object // https://discordapp.string.IsNullOrWhiteSpace(com/developers/docs/resources/guild#guild-object
public partial class Guild public partial class Guild : IHasId
{ {
public string Id { get; } public string Id { get; }

@ -0,0 +1,7 @@
namespace DiscordChatExporter.Core.Models
{
public interface IHasId
{
string Id { get; }
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
namespace DiscordChatExporter.Core.Models
{
public partial class IdBasedEqualityComparer : IEqualityComparer<IHasId>
{
public bool Equals(IHasId? x, IHasId? y) => StringComparer.Ordinal.Equals(x?.Id, y?.Id);
public int GetHashCode(IHasId obj) => StringComparer.Ordinal.GetHashCode(obj.Id);
}
public partial class IdBasedEqualityComparer
{
public static IdBasedEqualityComparer Instance { get; } = new IdBasedEqualityComparer();
}
}

@ -5,7 +5,7 @@ namespace DiscordChatExporter.Core.Models
{ {
// https://discordapp.com/developers/docs/resources/channel#message-object // https://discordapp.com/developers/docs/resources/channel#message-object
public class Message public class Message : IHasId
{ {
public string Id { get; } public string Id { get; }

@ -2,7 +2,7 @@
{ {
// https://discordapp.com/developers/docs/topics/permissions#role-object // https://discordapp.com/developers/docs/topics/permissions#role-object
public partial class Role public partial class Role : IHasId
{ {
public string Id { get; } public string Id { get; }

@ -4,7 +4,7 @@ namespace DiscordChatExporter.Core.Models
{ {
// https://discordapp.com/developers/docs/topics/permissions#role-object // https://discordapp.com/developers/docs/topics/permissions#role-object
public partial class User public partial class User : IHasId
{ {
public string Id { get; } public string Id { get; }

Loading…
Cancel
Save