Browse Source

Update ModalUtils.cs

methods: Modals, GetOrAdd<T>, TryGet<T>, TryRemove<T> was removed.
pull/2585/head
Zotov Oleksii GitHub 2 years ago
parent
commit
ee35a08e2a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 17 deletions
  1. +4
    -17
      src/Discord.Net.Interactions/Utilities/ModalUtils.cs

+ 4
- 17
src/Discord.Net.Interactions/Utilities/ModalUtils.cs View File

@@ -1,49 +1,36 @@
using Discord.Interactions.Builders;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace Discord.Interactions
{
internal static class ModalUtils
{
private static readonly ConcurrentDictionary<Type, ModalInfo> _modalInfos = new();

public static IReadOnlyCollection<ModalInfo> Modals => _modalInfos.Values.ToReadOnlyCollection();
private static readonly ConcurrentDictionary<Type, ModalInfo> _modalInfos = new ConcurrentDictionary<Type, ModalInfo>();

public static ModalInfo GetOrAdd(Type type, InteractionService interactionService)
{
if (!typeof(IModal).IsAssignableFrom(type))
throw new ArgumentException($"Must be an implementation of {nameof(IModal)}", nameof(type));
throw new ArgumentException($"Type must implement {nameof(IModal)}", nameof(type));

return _modalInfos.GetOrAdd(type, ModuleClassBuilder.BuildModalInfo(type, interactionService));
}

public static ModalInfo GetOrAdd<T>(InteractionService interactionService) where T : class, IModal
=> GetOrAdd(typeof(T), interactionService);

public static bool TryGet(Type type, out ModalInfo modalInfo)
{
if (!typeof(IModal).IsAssignableFrom(type))
throw new ArgumentException($"Must be an implementation of {nameof(IModal)}", nameof(type));
throw new ArgumentException($"Type must implement {nameof(IModal)}", nameof(type));

return _modalInfos.TryGetValue(type, out modalInfo);
}

public static bool TryGet<T>(out ModalInfo modalInfo) where T : class, IModal
=> TryGet(typeof(T), out modalInfo);

public static bool TryRemove(Type type, out ModalInfo modalInfo)
{
if (!typeof(IModal).IsAssignableFrom(type))
throw new ArgumentException($"Must be an implementation of {nameof(IModal)}", nameof(type));
throw new ArgumentException($"Type must implement {nameof(IModal)}", nameof(type));

return _modalInfos.TryRemove(type, out modalInfo);
}

public static bool TryRemove<T>(out ModalInfo modalInfo) where T : class, IModal
=> TryRemove(typeof(T), out modalInfo);

public static void Clear() => _modalInfos.Clear();

public static int Count() => _modalInfos.Count;


Loading…
Cancel
Save