Browse Source

Removed some C#7 stuff

tags/1.0-rc
RogueException 9 years ago
parent
commit
59e6b33cbb
2 changed files with 3 additions and 21 deletions
  1. +2
    -17
      src/Discord.Net/Entities/Permissions/ChannelPermissions.cs
  2. +1
    -4
      src/Discord.Net/Entities/Permissions/GuildPermissions.cs

+ 2
- 17
src/Discord.Net/Entities/Permissions/ChannelPermissions.cs View File

@@ -7,37 +7,22 @@ namespace Discord
[DebuggerDisplay("{DebuggerDisplay,nq}")] [DebuggerDisplay("{DebuggerDisplay,nq}")]
public struct ChannelPermissions public struct ChannelPermissions
{ {
#if CSHARP7
private static ChannelPermissions _allDM { get; } = new ChannelPermissions(0b000100_000000_0011111111_0000011001);
private static ChannelPermissions _allText { get; } = new ChannelPermissions(0b000000_000000_0001110011_0000000000);
private static ChannelPermissions _allVoice { get; } = new ChannelPermissions(0b000100_111111_0000000000_0000011001);
#else
//TODO: C#7 Candidate for binary literals
private static ChannelPermissions _allDM { get; } = new ChannelPermissions(Convert.ToUInt64("00010000000000111111110000011001", 2)); private static ChannelPermissions _allDM { get; } = new ChannelPermissions(Convert.ToUInt64("00010000000000111111110000011001", 2));
private static ChannelPermissions _allText { get; } = new ChannelPermissions(Convert.ToUInt64("00000000000000011100110000000000", 2)); private static ChannelPermissions _allText { get; } = new ChannelPermissions(Convert.ToUInt64("00000000000000011100110000000000", 2));
private static ChannelPermissions _allVoice { get; } = new ChannelPermissions(Convert.ToUInt64("00010011111100000000000000011001", 2)); private static ChannelPermissions _allVoice { get; } = new ChannelPermissions(Convert.ToUInt64("00010011111100000000000000011001", 2));
#endif


/// <summary> Gets a blank ChannelPermissions that grants no permissions. </summary> /// <summary> Gets a blank ChannelPermissions that grants no permissions. </summary>
public static ChannelPermissions None { get; } = new ChannelPermissions(); public static ChannelPermissions None { get; } = new ChannelPermissions();
/// <summary> Gets a ChannelPermissions that grants all permissions for a given channelType. </summary> /// <summary> Gets a ChannelPermissions that grants all permissions for a given channelType. </summary>
public static ChannelPermissions All(IChannel channel) public static ChannelPermissions All(IChannel channel)
{ {
#if CSHARP7
switch (channel)
{
case ITextChannel _: return _allText;
case IVoiceChannel _: return _allVoice;
case IDMChannel _: return _allDM;
default:
throw new ArgumentException("Unknown channel type", nameof(channel));
}
#else
//TODO: C#7 Candidate for typeswitch
if (channel is ITextChannel) return _allText; if (channel is ITextChannel) return _allText;
if (channel is IVoiceChannel) return _allVoice; if (channel is IVoiceChannel) return _allVoice;
if (channel is IDMChannel) return _allDM; if (channel is IDMChannel) return _allDM;


throw new ArgumentException("Unknown channel type", nameof(channel)); throw new ArgumentException("Unknown channel type", nameof(channel));
#endif
} }


/// <summary> Gets a packed value representing all the permissions in this ChannelPermissions. </summary> /// <summary> Gets a packed value representing all the permissions in this ChannelPermissions. </summary>


+ 1
- 4
src/Discord.Net/Entities/Permissions/GuildPermissions.cs View File

@@ -10,11 +10,8 @@ namespace Discord
/// <summary> Gets a blank GuildPermissions that grants no permissions. </summary> /// <summary> Gets a blank GuildPermissions that grants no permissions. </summary>
public static readonly GuildPermissions None = new GuildPermissions(); public static readonly GuildPermissions None = new GuildPermissions();
/// <summary> Gets a GuildPermissions that grants all permissions. </summary> /// <summary> Gets a GuildPermissions that grants all permissions. </summary>
#if CSHARP7
public static readonly GuildPermissions All = new GuildPermissions(0b000111_111111_0011111111_0000111111);
#else
//TODO: C#7 Candidate for binary literals
public static readonly GuildPermissions All = new GuildPermissions(Convert.ToUInt64("00011111111100111111110000111111", 2)); public static readonly GuildPermissions All = new GuildPermissions(Convert.ToUInt64("00011111111100111111110000111111", 2));
#endif


/// <summary> Gets a packed value representing all the permissions in this GuildPermissions. </summary> /// <summary> Gets a packed value representing all the permissions in this GuildPermissions. </summary>
public ulong RawValue { get; } public ulong RawValue { get; }


Loading…
Cancel
Save