Browse Source

Xml docs changes

pull/1487/head
SubZero0 5 years ago
parent
commit
bb2eb645b2
2 changed files with 33 additions and 12 deletions
  1. +10
    -11
      src/Discord.Net.Commands/CommandService.cs
  2. +23
    -1
      src/Discord.Net.Examples/Commands/CommandService.Examples.cs

+ 10
- 11
src/Discord.Net.Commands/CommandService.cs View File

@@ -82,8 +82,8 @@ namespace Discord.Commands
/// Represents all entity type reader <see cref="Type" />s loaded within <see cref="CommandService"/>. /// Represents all entity type reader <see cref="Type" />s loaded within <see cref="CommandService"/>.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// A <see cref="ILookup{TKey, TElement}"/> that the key is the object type to be read by the <see cref="TypeReader"/>
/// and the element is the type of the <see cref="TypeReader"/> generic definition.
/// A <see cref="ILookup{TKey, TElement}"/>; the key is the object type to be read by the <see cref="TypeReader"/>,
/// while the element is the type of the <see cref="TypeReader"/> generic definition.
/// </returns> /// </returns>
public ILookup<Type, Type> EntityTypeReaders => _userEntityTypeReaders.SelectMany(x => x.Value.Select(y => new { x.Key, TypeReaderType = y })).ToLookup(x => x.Key, y => y.TypeReaderType); public ILookup<Type, Type> EntityTypeReaders => _userEntityTypeReaders.SelectMany(x => x.Value.Select(y => new { x.Key, TypeReaderType = y })).ToLookup(x => x.Key, y => y.TypeReaderType);


@@ -368,13 +368,10 @@ namespace Discord.Commands
/// <example> /// <example>
/// <para>The following example adds a custom entity reader to this <see cref="CommandService"/>.</para> /// <para>The following example adds a custom entity reader to this <see cref="CommandService"/>.</para>
/// <code language="cs" region="AddEntityTypeReader" /// <code language="cs" region="AddEntityTypeReader"
/// source="..\..\..\Discord.Net.Examples\Commands\CommandService.Examples.cs" />
/// source="..\Discord.Net.Examples\Commands\CommandService.Examples.cs" />
/// </example> /// </example>
/// <typeparam name="T">The object type to be read by the <see cref="TypeReader"/>.</typeparam> /// <typeparam name="T">The object type to be read by the <see cref="TypeReader"/>.</typeparam>
/// <param name="typeReaderGenericType">
/// A <see cref="Type" /> that is a generic type definition with a single open argument
/// of the <see cref="TypeReader" /> to be added.
/// </param>
/// <param name="typeReaderGenericType">A generic type definition (with one open argument) of the <see cref="TypeReader" />.</param>
public void AddEntityTypeReader<T>(Type typeReaderGenericType) public void AddEntityTypeReader<T>(Type typeReaderGenericType)
=> AddEntityTypeReader(typeof(T), typeReaderGenericType); => AddEntityTypeReader(typeof(T), typeReaderGenericType);
/// <summary> /// <summary>
@@ -382,10 +379,7 @@ namespace Discord.Commands
/// object type. /// object type.
/// </summary> /// </summary>
/// <param name="type">A <see cref="Type" /> instance for the type to be read.</param> /// <param name="type">A <see cref="Type" /> instance for the type to be read.</param>
/// <param name="typeReaderGenericType">
/// A <see cref="Type" /> that is a generic type definition with a single open argument
/// of the <see cref="TypeReader" /> to be added.
/// </param>
/// <param name="typeReaderGenericType">A generic type definition (with one open argument) of the <see cref="TypeReader" />.</param>
public void AddEntityTypeReader(Type type, Type typeReaderGenericType) public void AddEntityTypeReader(Type type, Type typeReaderGenericType)
{ {
if (!typeReaderGenericType.IsGenericTypeDefinition) if (!typeReaderGenericType.IsGenericTypeDefinition)
@@ -406,6 +400,11 @@ namespace Discord.Commands
/// If <typeparamref name="T" /> is a <see cref="ValueType" />, a nullable <see cref="TypeReader" /> will /// If <typeparamref name="T" /> is a <see cref="ValueType" />, a nullable <see cref="TypeReader" /> will
/// also be added. /// also be added.
/// </summary> /// </summary>
/// <example>
/// <para>The following example adds a custom entity reader to this <see cref="CommandService"/>.</para>
/// <code language="cs" region="AddEntityTypeReader2"
/// source="..\Discord.Net.Examples\Commands\CommandService.Examples.cs" />
/// </example>
/// <typeparam name="T">The object type to be read by the <see cref="TypeReader"/>.</typeparam> /// <typeparam name="T">The object type to be read by the <see cref="TypeReader"/>.</typeparam>
/// <param name="reader">An instance of the <see cref="TypeReader" /> to be added.</param> /// <param name="reader">An instance of the <see cref="TypeReader" /> to be added.</param>
/// <param name="replaceDefault"> /// <param name="replaceDefault">


+ 23
- 1
src/Discord.Net.Examples/Commands/CommandService.Examples.cs View File

@@ -10,7 +10,7 @@ namespace Discord.Net.Examples.Commands
{ {
#region AddEntityTypeReader #region AddEntityTypeReader


public void AddCustomEntityReader(CommandService commandService)
public void AddCustomUserEntityReader(CommandService commandService)
{ {
commandService.AddEntityTypeReader<IUser>(typeof(MyUserTypeReader<>)); commandService.AddEntityTypeReader<IUser>(typeof(MyUserTypeReader<>));
} }
@@ -29,5 +29,27 @@ namespace Discord.Net.Examples.Commands
} }


#endregion #endregion

#region AddEntityTypeReader2

public void AddCustomChannelEntityReader(CommandService commandService)
{
commandService.AddEntityTypeReader<IUser>(typeof(MyUserTypeReader<>));
}

public class MyChannelTypeReader<T> : TypeReader
where T : class, IChannel
{
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
{
if (ulong.TryParse(input, out var id))
return ((await context.Client.GetChannelAsync(id)) is T channel)
? TypeReaderResult.FromSuccess(channel)
: TypeReaderResult.FromError(CommandError.ObjectNotFound, "Channel not found.");
return TypeReaderResult.FromError(CommandError.ParseFailed, "Couldn't parse input to ulong.");
}
}

#endregion
} }
} }

Loading…
Cancel
Save