Browse Source

Finalizing docs work, resolving docfx errors.

pull/2054/head
Armano den Boef 3 years ago
parent
commit
25c86aab79
7 changed files with 21 additions and 30 deletions
  1. +1
    -1
      docs/faq/basics/basic-operations.md
  2. +9
    -9
      docs/guides/entities/casting.md
  3. +10
    -10
      docs/guides/entities/glossary.md
  4. +1
    -1
      docs/guides/entities/samples/casting.cs
  5. +0
    -6
      docs/guides/entities/samples/safety-cast.cs
  6. +0
    -2
      docs/guides/toc.yml
  7. +0
    -1
      samples/InteractionFramework/Modules/GeneralModule.cs

+ 1
- 1
docs/faq/basics/basic-operations.md View File

@@ -53,7 +53,7 @@ able to message.
You may check the message channel type. Visit [Glossary] to see the
various types of channels.

[glossary]: xref:FAQ.Glossary#message-channels
[Glossary]: xref:Guides.Entities.Glossary#channels

## How can I get the guild from a message?



+ 9
- 9
docs/guides/entities/casting.md View File

@@ -10,7 +10,7 @@ Casting only works for types that inherit the base type that you want to unbox f
`IUser` cannot be cast to `IMessage`.

> [!NOTE]
> Interfaces CAN be cast to other interfaces, as long as they inherit eachother.
> Interfaces **can** be cast to other interfaces, as long as they inherit eachother.
> The same goes for reverse casting. As long as some entity can be simplified into what it inherits, your cast will pass.

## Boxing
@@ -25,17 +25,17 @@ Through casting, we can **unbox** this type, and access the properties that were
Unboxing is the most direct way to access the real definition of an object.
If we want to return a type from its interface, we can unbox it directly.

[!code-csharp[Unboxing](images/unboxing.cs)]
[!code-csharp[Unboxing](samples/unboxing.cs)]

## Regular casting

In 'regular' casting, we use the ` as ` keyword to assign the given type to the object.
In 'regular' casting, we use the `as` keyword to assign the given type to the object.
If the boxed type can indeed be cast into given type,
it will become said type, and its properties can be accessed.
[!code-csharp[Casting](images/casting.cs)]
[!code-csharp[Casting](samples/casting.cs)]

> [!WARNING]
> If the type you're casting to is null, a ` NullReferenceException ` will be thrown when its called.
> If the type you're casting to is null, a `NullReferenceException` will be thrown when its called.
> This makes safety casting much more interesting to use, as it prevents this exception from being thrown.

## Safety casting
@@ -48,21 +48,21 @@ There are 3 different ways to safety cast an object:

To safety cast an object, all we need to do is check if it is of the member type in a statement.
If this check fails, it will continue below, making sure we don't try to access null.
[!code-csharp[Base](images/safety-cast.cs)]
[!code-csharp[Base](samples/safety-cast.cs)]

### Object declaration:

Here we declare the object we are casting to,
making it so that you can immediately work with its properties without reassigning through regular casting.
[!code-csharp[Declare](images/safety-cast-var.cs)]
[!code-csharp[Declare](samples/safety-cast-var.cs)]

### Reverse passage:

In previous examples, we want to let code continue running after the check, or if the check fails.
In this example, the cast will return the entire method (ignoring the latter) upon failure,
and declare the variable for further use into the method:
[!code-csharp[Pass](images/safety-cast-pass.cs)]
[!code-csharp[Pass](samples/safety-cast-pass.cs)]

> [!NOTE]
> Usage of ` is `, ` not ` and ` as ` is required in cast assignment and/or type checks. ==, != and = are invalid assignment,
> Usage of `is`, `not` and `as` is required in cast assignment and/or type checks. `==`, `!=` and `=` are invalid assignment,
> as these operators only apply to initialized objects and not their types.

+ 10
- 10
docs/guides/entities/glossary.md View File

@@ -7,7 +7,7 @@ title: Glossary & Flowcharts

A list of all Discord.Net entities, what they can be cast to and what their properties are.

> [!IMPORTANT]
> [!NOTE]
> All interfaces have the same inheritance tree for both `Socket` and `Rest` entities.
> Entities with that have been marked red are exclusive to the project they source from.

@@ -53,8 +53,8 @@ exist under a category.

![IMessageChart](images/IMessage.png)

* A **Rest Followup Message ([RestFollowupMessage]) is a message returned by followup on on an interaction.
* A **Rest Interaction Message ([RestInteractionMessage]) is a message returned by the interactions' original response.
* A **Rest Followup Message** ([RestFollowupMessage]) is a message returned by followup on on an interaction.
* A **Rest Interaction Message** ([RestInteractionMessage]) is a message returned by the interactions' original response.
* A **Rest User Message** ([RestUserMessage]) is a message sent over rest, can be any of the above.
* An **User Message** ([IUserMessage]) is a message sent by a user.
* A **System Message** ([ISystemMessage]) is a message sent by Discord itself.
@@ -94,13 +94,13 @@ exist under a category.
* An **Autocomplete Interaction** ([IAutocompleteinteraction]) is an interaction that has been automatically completed.
* An **Interaction** ([IDiscordInteraction]) is any of the above.

[ISlashCommandInteraction] xref: Discord.ISlashCommandInteraction
[IMessageCommandInteraction] xref: Discord.IMessageCommandInteraction
[IUserCommandInteraction] xref: Discord.IUserCommandInteraction
[IApplicationCommandInteraction] xref: Discord.IApplicationCommandInteraction
[IMessageComponent] xref: Discord.IMessageComponent
[IAutocompleteinteraction] xref: Discord.IAutocompleteInteraction
[IDiscordInteraction] xref: Discord.IDiscordInteraction
[ISlashCommandInteraction]: xref: Discord.ISlashCommandInteraction
[IMessageCommandInteraction]: xref: Discord.IMessageCommandInteraction
[IUserCommandInteraction]: xref: Discord.IUserCommandInteraction
[IApplicationCommandInteraction]: xref: Discord.IApplicationCommandInteraction
[IMessageComponent]: xref: Discord.IMessageComponent
[IAutocompleteinteraction]: xref: Discord.IAutocompleteInteraction
[IDiscordInteraction]: xref: Discord.IDiscordInteraction

## Other types:



+ 1
- 1
docs/guides/entities/samples/casting.cs View File

@@ -1,7 +1,7 @@
// Say we have an entity, for the simplicity of this example, it will appear from thin air.
IChannel channel;

// If I want this to be an ITextChannel so I can access the properties of a text channel inside of a guild, an approach would be:
// If we want this to be an ITextChannel so we can access the properties of a text channel inside of a guild, an approach would be:
ITextChannel textChannel = channel as ITextChannel;

await textChannel.DoSomethingICantWithIChannelAsync();

+ 0
- 6
docs/guides/entities/samples/safety-cast.cs View File

@@ -6,9 +6,3 @@ if (user is IGuildUser)
Console.WriteLine("This user is in a guild!");
}
// Check failed.

----------------------------
// Another situation, where we want to get the actual data of said IGuildUser.

----------------------------
// A final situation, where we dont actually need to do anything code-wise when the check does not pass, so we want to simplify it.

+ 0
- 2
docs/guides/toc.yml View File

@@ -21,8 +21,6 @@
topicUid: Guides.Concepts.Events
- name: Managing Connections
topicUid: Guides.Concepts.ManageConnections
- name: Entities
topicUid: Guides.Concepts.Entities
- name: Entities
items:
- name: Introduction


+ 0
- 1
samples/InteractionFramework/Modules/GeneralModule.cs View File

@@ -1,6 +1,5 @@
using Discord;
using Discord.Interactions;
using InteractionFramework.Attributes;
using System.Threading.Tasks;

namespace InteractionFramework.Modules


Loading…
Cancel
Save