From d189bb97489412d47b165f836abdbe182cf7d855 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Thu, 4 May 2017 11:53:40 -0400 Subject: [PATCH] Expose the 'fields' collection on EmbedBuilder (#603) * remove tip in docs about SocketEntity.Discord * Expose the 'Fields' collection on EmbedBuilder After some discussion I decided that there was really no reason to keep this private, and it didn't really go along with the rest of the design of the EmbedBuilder. This is NOT a breaking change. Exposing this property should not have any negative effects. * Don't allow EmbedBuilder's Fields to be set to null --- docs/guides/concepts/entities.md | 3 --- .../Entities/Messages/EmbedBuilder.cs | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/guides/concepts/entities.md b/docs/guides/concepts/entities.md index b753293bb..a38651829 100644 --- a/docs/guides/concepts/entities.md +++ b/docs/guides/concepts/entities.md @@ -35,9 +35,6 @@ you to easily navigate to an entity's parent or children. As explained above, you will sometimes need to cast to a more detailed version of an entity to navigate to its parent. -All socket entities have a `Discord` property, which will allow you -to access the parent `DiscordSocketClient`. - ### Accessing Entities The most basic forms of entities, `SocketGuild`, `SocketUser`, and diff --git a/src/Discord.Net.Rest/Entities/Messages/EmbedBuilder.cs b/src/Discord.Net.Rest/Entities/Messages/EmbedBuilder.cs index 74f1441e1..98a191379 100644 --- a/src/Discord.Net.Rest/Entities/Messages/EmbedBuilder.cs +++ b/src/Discord.Net.Rest/Entities/Messages/EmbedBuilder.cs @@ -7,12 +7,11 @@ namespace Discord public class EmbedBuilder { private readonly Embed _embed; - private readonly List _fields; public EmbedBuilder() { _embed = new Embed("rich"); - _fields = new List(); + Fields = new List(); } public string Title { get { return _embed.Title; } set { _embed.Title = value; } } @@ -25,6 +24,16 @@ namespace Discord public EmbedAuthorBuilder Author { get; set; } public EmbedFooterBuilder Footer { get; set; } + private List _fields; + public List Fields + { + get => _fields; + set + { + if (value != null) _fields = value; + else throw new ArgumentNullException("Cannot set an embed builder's fields collection to null", nameof(value)); + } + } public EmbedBuilder WithTitle(string title) { @@ -98,7 +107,7 @@ namespace Discord .WithIsInline(false) .WithName(name) .WithValue(value); - _fields.Add(field); + Fields.Add(field); return this; } public EmbedBuilder AddInlineField(string name, object value) @@ -107,19 +116,19 @@ namespace Discord .WithIsInline(true) .WithName(name) .WithValue(value); - _fields.Add(field); + Fields.Add(field); return this; } public EmbedBuilder AddField(EmbedFieldBuilder field) { - _fields.Add(field); + Fields.Add(field); return this; } public EmbedBuilder AddField(Action action) { var field = new EmbedFieldBuilder(); action(field); - _fields.Add(field); + Fields.Add(field); return this; } @@ -127,9 +136,9 @@ namespace Discord { _embed.Footer = Footer?.Build(); _embed.Author = Author?.Build(); - var fields = ImmutableArray.CreateBuilder(_fields.Count); - for (int i = 0; i < _fields.Count; i++) - fields.Add(_fields[i].Build()); + var fields = ImmutableArray.CreateBuilder(Fields.Count); + for (int i = 0; i < Fields.Count; i++) + fields.Add(Fields[i].Build()); _embed.Fields = fields.ToImmutable(); return _embed; }