Added missing ToString and DebuggerDisplays

This commit is contained in:
RogueException
2016-10-04 16:41:40 -03:00
parent e70d478759
commit 7df38fea3a
28 changed files with 75 additions and 27 deletions

View File

@@ -1,13 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.Channel; using Model = Discord.API.Channel;
namespace Discord.Rest namespace Discord.Rest
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public abstract class RestChannel : RestEntity<ulong>, IChannel, IUpdateable public abstract class RestChannel : RestEntity<ulong>, IChannel, IUpdateable
{ {
internal RestChannel(BaseDiscordClient discord, ulong id) internal RestChannel(BaseDiscordClient discord, ulong id)

View File

@@ -76,7 +76,6 @@ namespace Discord.Rest
public override string ToString() => $"@{Recipient}"; public override string ToString() => $"@{Recipient}";
private string DebuggerDisplay => $"@{Recipient} ({Id}, DM)"; private string DebuggerDisplay => $"@{Recipient} ({Id}, DM)";
//IDMChannel //IDMChannel
IUser IDMChannel.Recipient => Recipient; IUser IDMChannel.Recipient => Recipient;

View File

@@ -86,6 +86,9 @@ namespace Discord.Rest
public IDisposable EnterTypingState() public IDisposable EnterTypingState()
=> ChannelHelper.EnterTypingState(this, Discord); => ChannelHelper.EnterTypingState(this, Discord);
public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id}, Group)";
//ISocketPrivateChannel //ISocketPrivateChannel
IReadOnlyCollection<RestUser> IRestPrivateChannel.Recipients => Recipients; IReadOnlyCollection<RestUser> IRestPrivateChannel.Recipients => Recipients;

View File

@@ -2,14 +2,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.Channel; using Model = Discord.API.Channel;
namespace Discord.Rest namespace Discord.Rest
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public abstract class RestGuildChannel : RestChannel, IGuildChannel, IUpdateable public abstract class RestGuildChannel : RestChannel, IGuildChannel, IUpdateable
{ {
private ImmutableArray<Overwrite> _overwrites; private ImmutableArray<Overwrite> _overwrites;
@@ -117,7 +115,9 @@ namespace Discord.Rest
=> await ChannelHelper.GetInvitesAsync(this, Discord); => await ChannelHelper.GetInvitesAsync(this, Discord);
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true) public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary); => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary);
public override string ToString() => Name;
//IGuildChannel //IGuildChannel
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync() async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync()
=> await GetInvitesAsync(); => await GetInvitesAsync();

View File

@@ -1,7 +1,6 @@
using Discord.API.Rest; using Discord.API.Rest;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -67,6 +66,8 @@ namespace Discord.Rest
public IDisposable EnterTypingState() public IDisposable EnterTypingState()
=> ChannelHelper.EnterTypingState(this, Discord); => ChannelHelper.EnterTypingState(this, Discord);
private string DebuggerDisplay => $"{Name} ({Id}, Text)";
//IGuildChannel //IGuildChannel
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode) async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
{ {

View File

@@ -2,7 +2,6 @@
using Discord.Audio; using Discord.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -37,6 +36,8 @@ namespace Discord.Rest
public Task ModifyAsync(Action<ModifyVoiceChannelParams> func) public Task ModifyAsync(Action<ModifyVoiceChannelParams> func)
=> ChannelHelper.ModifyAsync(this, Discord, func); => ChannelHelper.ModifyAsync(this, Discord, func);
private string DebuggerDisplay => $"{Name} ({Id}, Voice)";
//IVoiceChannel //IVoiceChannel
Task<IAudioClient> IVoiceChannel.ConnectAsync() { throw new NotSupportedException(); } Task<IAudioClient> IVoiceChannel.ConnectAsync() { throw new NotSupportedException(); }

View File

@@ -22,6 +22,7 @@ namespace Discord.Rest
public override string ToString() => User.ToString(); public override string ToString() => User.ToString();
private string DebuggerDisplay => $"{User}: {Reason}"; private string DebuggerDisplay => $"{User}: {Reason}";
//IBan
IUser IBan.User => User; IUser IBan.User => User;
} }
} }

View File

@@ -171,6 +171,9 @@ namespace Discord.Rest
public Task<int> PruneUsersAsync(int days = 30, bool simulate = false) public Task<int> PruneUsersAsync(int days = 30, bool simulate = false)
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate); => GuildHelper.PruneUsersAsync(this, Discord, days, simulate);
public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id})";
//IGuild //IGuild
bool IGuild.Available => Available; bool IGuild.Available => Available;
IAudioClient IGuild.AudioClient => null; IAudioClient IGuild.AudioClient => null;

View File

@@ -4,7 +4,6 @@ using Model = Discord.API.InviteMetadata;
namespace Discord.Rest namespace Discord.Rest
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class RestInviteMetadata : RestInvite, IInviteMetadata public class RestInviteMetadata : RestInvite, IInviteMetadata
{ {
private long _createdAtTicks; private long _createdAtTicks;

View File

@@ -1,8 +1,9 @@
using Model = Discord.API.Attachment; using System.Diagnostics;
using Model = Discord.API.Attachment;
namespace Discord namespace Discord
{ {
//TODO: Rename to Attachment? [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class RestAttachment : IAttachment public class RestAttachment : IAttachment
{ {
public ulong Id { get; } public ulong Id { get; }
@@ -29,5 +30,8 @@ namespace Discord
model.Height.IsSpecified ? model.Height.Value : (int?)null, model.Height.IsSpecified ? model.Height.Value : (int?)null,
model.Width.IsSpecified ? model.Width.Value : (int?)null); model.Width.IsSpecified ? model.Width.Value : (int?)null);
} }
public override string ToString() => Filename;
private string DebuggerDisplay => $"{Filename} ({Size} bytes)";
} }
} }

View File

@@ -1,7 +1,9 @@
using Model = Discord.API.Embed; using System.Diagnostics;
using Model = Discord.API.Embed;
namespace Discord namespace Discord
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class RestEmbed : IEmbed public class RestEmbed : IEmbed
{ {
public string Description { get; } public string Description { get; }
@@ -26,5 +28,8 @@ namespace Discord
model.Provider.IsSpecified ? EmbedProvider.Create(model.Provider.Value) : (EmbedProvider?)null, model.Provider.IsSpecified ? EmbedProvider.Create(model.Provider.Value) : (EmbedProvider?)null,
model.Thumbnail.IsSpecified ? EmbedThumbnail.Create(model.Thumbnail.Value) : (EmbedThumbnail?)null); model.Thumbnail.IsSpecified ? EmbedThumbnail.Create(model.Thumbnail.Value) : (EmbedThumbnail?)null);
} }
public override string ToString() => Title;
private string DebuggerDisplay => $"{Title} ({Type})";
} }
} }

View File

@@ -1,13 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.Message; using Model = Discord.API.Message;
namespace Discord.Rest namespace Discord.Rest
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public abstract class RestMessage : RestEntity<ulong>, IMessage, IUpdateable public abstract class RestMessage : RestEntity<ulong>, IMessage, IUpdateable
{ {
private long _timestampTicks; private long _timestampTicks;
@@ -56,6 +54,8 @@ namespace Discord.Rest
Update(model); Update(model);
} }
public override string ToString() => Content;
MessageType IMessage.Type => MessageType.Default; MessageType IMessage.Type => MessageType.Default;
} }
} }

View File

@@ -24,5 +24,7 @@ namespace Discord.Rest
Type = model.Type; Type = model.Type;
} }
private string DebuggerDisplay => $"{Author}: {Content} ({Id}, {Type})";
} }
} }

View File

@@ -130,5 +130,7 @@ namespace Discord.Rest
text = MentionsHelper.ResolveEveryoneMentions(text, everyoneHandling); text = MentionsHelper.ResolveEveryoneMentions(text, everyoneHandling);
return text; return text;
} }
private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")}";
} }
} }

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.Application; using Model = Discord.API.Application;
namespace Discord.Rest namespace Discord.Rest
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class RestApplication : RestEntity<ulong>, IApplication public class RestApplication : RestEntity<ulong>, IApplication
{ {
protected string _iconId; protected string _iconId;
@@ -27,7 +29,6 @@ namespace Discord.Rest
entity.Update(model); entity.Update(model);
return entity; return entity;
} }
internal void Update(Model model) internal void Update(Model model)
{ {
Description = model.Description; Description = model.Description;
@@ -45,5 +46,8 @@ namespace Discord.Rest
throw new InvalidOperationException("Unable to update this object from a different application token."); throw new InvalidOperationException("Unable to update this object from a different application token.");
Update(response); Update(response);
} }
public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id})";
} }
} }

View File

@@ -46,6 +46,9 @@ namespace Discord.Rest
public Task DeleteAsync() public Task DeleteAsync()
=> RoleHelper.DeleteAsync(this, Discord); => RoleHelper.DeleteAsync(this, Discord);
public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id})";
//IRole //IRole
IGuild IRole.Guild => Guild; IGuild IRole.Guild => Guild;
} }

View File

@@ -30,6 +30,6 @@ namespace Discord
} }
public override string ToString() => Name; public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id}, Type = {Type}{(IsRevoked ? ", Revoked" : "")})"; private string DebuggerDisplay => $"{Name} ({Id}, {Type}{(IsRevoked ? ", Revoked" : "")})";
} }
} }

View File

@@ -46,6 +46,10 @@ namespace Discord.Rest
public Task<RestDMChannel> CreateDMChannelAsync() public Task<RestDMChannel> CreateDMChannelAsync()
=> UserHelper.CreateDMChannelAsync(this, Discord); => UserHelper.CreateDMChannelAsync(this, Discord);
public override string ToString() => $"{Username}#{Discriminator}";
internal string DebuggerDisplay => $"{Username}#{Discriminator} (Id{(IsBot ? ", Bot" : "")})";
//IUser
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode) Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode)
=> Task.FromResult<IDMChannel>(null); => Task.FromResult<IDMChannel>(null);
async Task<IDMChannel> IUser.CreateDMChannelAsync() async Task<IDMChannel> IUser.CreateDMChannelAsync()

View File

@@ -6,7 +6,6 @@ using Model = Discord.API.Message;
namespace Discord.WebSocket namespace Discord.WebSocket
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public abstract class SocketMessage : SocketEntity<ulong>, IMessage public abstract class SocketMessage : SocketEntity<ulong>, IMessage
{ {
private long _timestampTicks; private long _timestampTicks;
@@ -49,7 +48,8 @@ namespace Discord.WebSocket
if (model.Content.IsSpecified) if (model.Content.IsSpecified)
Content = model.Content.Value; Content = model.Content.Value;
} }
public override string ToString() => Content;
internal SocketMessage Clone() => MemberwiseClone() as SocketMessage; internal SocketMessage Clone() => MemberwiseClone() as SocketMessage;
//IMessage //IMessage

View File

@@ -1,7 +1,9 @@
using Model = Discord.API.Message; using System.Diagnostics;
using Model = Discord.API.Message;
namespace Discord.WebSocket namespace Discord.WebSocket
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
internal class SocketSystemMessage : SocketMessage, ISystemMessage internal class SocketSystemMessage : SocketMessage, ISystemMessage
{ {
public MessageType Type { get; private set; } public MessageType Type { get; private set; }
@@ -22,8 +24,7 @@ namespace Discord.WebSocket
Type = model.Type; Type = model.Type;
} }
public override string ToString() => Content;
private string DebuggerDisplay => $"{Author}: {Content} ({Id}, {Type})"; private string DebuggerDisplay => $"{Author}: {Content} ({Id}, {Type})";
internal new SocketSystemMessage Clone() => MemberwiseClone() as SocketSystemMessage; internal new SocketSystemMessage Clone() => MemberwiseClone() as SocketSystemMessage;
} }

View File

@@ -3,11 +3,13 @@ using Discord.Rest;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.Message; using Model = Discord.API.Message;
namespace Discord.WebSocket namespace Discord.WebSocket
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketUserMessage : SocketMessage, IUserMessage public class SocketUserMessage : SocketMessage, IUserMessage
{ {
private bool _isMentioningEveryone, _isTTS, _isPinned; private bool _isMentioningEveryone, _isTTS, _isPinned;
@@ -131,7 +133,6 @@ namespace Discord.WebSocket
return text; return text;
} }
public override string ToString() => Content;
private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")}"; private string DebuggerDisplay => $"{Author}: {Content} ({Id}{(Attachments.Count > 0 ? $", {Attachments.Count} Attachments" : "")}";
internal new SocketUserMessage Clone() => MemberwiseClone() as SocketUserMessage; internal new SocketUserMessage Clone() => MemberwiseClone() as SocketUserMessage;
} }

View File

@@ -1,7 +1,9 @@
using Model = Discord.API.User; using System.Diagnostics;
using Model = Discord.API.User;
namespace Discord.WebSocket namespace Discord.WebSocket
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
internal class SocketGlobalUser : SocketUser internal class SocketGlobalUser : SocketUser
{ {
public override bool IsBot { get; internal set; } public override bool IsBot { get; internal set; }

View File

@@ -3,12 +3,14 @@ using Discord.Rest;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.GuildMember; using Model = Discord.API.GuildMember;
using PresenceModel = Discord.API.Presence; using PresenceModel = Discord.API.Presence;
namespace Discord.WebSocket namespace Discord.WebSocket
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketGuildUser : SocketUser, IGuildUser public class SocketGuildUser : SocketUser, IGuildUser
{ {
private long? _joinedAtTicks; private long? _joinedAtTicks;

View File

@@ -1,8 +1,10 @@
using Model = Discord.API.Presence; using System.Diagnostics;
using Model = Discord.API.Presence;
namespace Discord.WebSocket namespace Discord.WebSocket
{ {
//TODO: C#7 Candidate for record type //TODO: C#7 Candidate for record type
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public struct SocketPresence : IPresence public struct SocketPresence : IPresence
{ {
public Game? Game { get; } public Game? Game { get; }
@@ -18,6 +20,9 @@ namespace Discord.WebSocket
return new SocketPresence(model.Game != null ? Discord.Game.Create(model.Game) : (Game?)null, model.Status); return new SocketPresence(model.Game != null ? Discord.Game.Create(model.Game) : (Game?)null, model.Status);
} }
public override string ToString() => Status.ToString();
internal string DebuggerDisplay => $"{Status}{(Game != null ? $", {Game.Value.Name} ({Game.Value.StreamType})" : "")}";
internal SocketPresence Clone() => this; internal SocketPresence Clone() => this;
} }
} }

View File

@@ -1,11 +1,13 @@
using Discord.API.Rest; using Discord.API.Rest;
using Discord.Rest; using Discord.Rest;
using System; using System;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Model = Discord.API.User; using Model = Discord.API.User;
namespace Discord.WebSocket namespace Discord.WebSocket
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketSelfUser : SocketUser, ISelfUser public class SocketSelfUser : SocketUser, ISelfUser
{ {
public string Email { get; private set; } public string Email { get; private set; }

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Diagnostics;
using Model = Discord.API.User; using Model = Discord.API.User;
using PresenceModel = Discord.API.Presence; using PresenceModel = Discord.API.Presence;
namespace Discord.WebSocket namespace Discord.WebSocket
{ {
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketSimpleUser : SocketUser public class SocketSimpleUser : SocketUser
{ {
public override bool IsBot { get; internal set; } public override bool IsBot { get; internal set; }

View File

@@ -44,7 +44,7 @@ namespace Discord.WebSocket
=> UserHelper.CreateDMChannelAsync(this, Discord); => UserHelper.CreateDMChannelAsync(this, Discord);
public override string ToString() => $"{Username}#{Discriminator}"; public override string ToString() => $"{Username}#{Discriminator}";
private string DebuggerDisplay => $"{Username}#{Discriminator} (Id{(IsBot ? ", Bot" : "")})"; internal string DebuggerDisplay => $"{Username}#{Discriminator} (Id{(IsBot ? ", Bot" : "")})";
internal SocketUser Clone() => MemberwiseClone() as SocketUser; internal SocketUser Clone() => MemberwiseClone() as SocketUser;
//IUser //IUser

View File

@@ -1,15 +1,17 @@
using System; using System;
using System.Diagnostics;
using Model = Discord.API.VoiceState; using Model = Discord.API.VoiceState;
namespace Discord.WebSocket namespace Discord.WebSocket
{ {
//TODO: C#7 Candidate for record type //TODO: C#7 Candidate for record type
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public struct SocketVoiceState : IVoiceState public struct SocketVoiceState : IVoiceState
{ {
[Flags] [Flags]
private enum Flags : byte private enum Flags : byte
{ {
None = 0x00, Normal = 0x00,
Suppressed = 0x01, Suppressed = 0x01,
Muted = 0x02, Muted = 0x02,
Deafened = 0x04, Deafened = 0x04,
@@ -33,7 +35,7 @@ namespace Discord.WebSocket
VoiceChannel = voiceChannel; VoiceChannel = voiceChannel;
VoiceSessionId = sessionId; VoiceSessionId = sessionId;
Flags voiceStates = Flags.None; Flags voiceStates = Flags.Normal;
if (isSelfMuted) if (isSelfMuted)
voiceStates |= Flags.SelfMuted; voiceStates |= Flags.SelfMuted;
if (isSelfDeafened) if (isSelfDeafened)
@@ -47,6 +49,8 @@ namespace Discord.WebSocket
return new SocketVoiceState(voiceChannel, model.SessionId, model.SelfMute, model.SelfDeaf, model.Suppress); return new SocketVoiceState(voiceChannel, model.SessionId, model.SelfMute, model.SelfDeaf, model.Suppress);
} }
public override string ToString() => VoiceChannel?.Name ?? "Unknown";
internal string DebuggerDisplay => $"{VoiceChannel?.Name ?? "Unknown"} ({_voiceStates})";
internal SocketVoiceState Clone() => this; internal SocketVoiceState Clone() => this;
IVoiceChannel IVoiceState.VoiceChannel => VoiceChannel; IVoiceChannel IVoiceState.VoiceChannel => VoiceChannel;