Browse Source

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.
pull/603/head
Christopher F 8 years ago
parent
commit
fbce842979
1 changed files with 9 additions and 9 deletions
  1. +9
    -9
      src/Discord.Net.Rest/Entities/Messages/EmbedBuilder.cs

+ 9
- 9
src/Discord.Net.Rest/Entities/Messages/EmbedBuilder.cs View File

@@ -7,12 +7,11 @@ namespace Discord
public class EmbedBuilder public class EmbedBuilder
{ {
private readonly Embed _embed; private readonly Embed _embed;
private readonly List<EmbedFieldBuilder> _fields;


public EmbedBuilder() public EmbedBuilder()
{ {
_embed = new Embed("rich"); _embed = new Embed("rich");
_fields = new List<EmbedFieldBuilder>();
Fields = new List<EmbedFieldBuilder>();
} }


public string Title { get { return _embed.Title; } set { _embed.Title = value; } } public string Title { get { return _embed.Title; } set { _embed.Title = value; } }
@@ -25,6 +24,7 @@ namespace Discord


public EmbedAuthorBuilder Author { get; set; } public EmbedAuthorBuilder Author { get; set; }
public EmbedFooterBuilder Footer { get; set; } public EmbedFooterBuilder Footer { get; set; }
public List<EmbedFieldBuilder> Fields { get; set; }


public EmbedBuilder WithTitle(string title) public EmbedBuilder WithTitle(string title)
{ {
@@ -98,7 +98,7 @@ namespace Discord
.WithIsInline(false) .WithIsInline(false)
.WithName(name) .WithName(name)
.WithValue(value); .WithValue(value);
_fields.Add(field);
Fields.Add(field);
return this; return this;
} }
public EmbedBuilder AddInlineField(string name, object value) public EmbedBuilder AddInlineField(string name, object value)
@@ -107,19 +107,19 @@ namespace Discord
.WithIsInline(true) .WithIsInline(true)
.WithName(name) .WithName(name)
.WithValue(value); .WithValue(value);
_fields.Add(field);
Fields.Add(field);
return this; return this;
} }
public EmbedBuilder AddField(EmbedFieldBuilder field) public EmbedBuilder AddField(EmbedFieldBuilder field)
{ {
_fields.Add(field);
Fields.Add(field);
return this; return this;
} }
public EmbedBuilder AddField(Action<EmbedFieldBuilder> action) public EmbedBuilder AddField(Action<EmbedFieldBuilder> action)
{ {
var field = new EmbedFieldBuilder(); var field = new EmbedFieldBuilder();
action(field); action(field);
_fields.Add(field);
Fields.Add(field);
return this; return this;
} }


@@ -127,9 +127,9 @@ namespace Discord
{ {
_embed.Footer = Footer?.Build(); _embed.Footer = Footer?.Build();
_embed.Author = Author?.Build(); _embed.Author = Author?.Build();
var fields = ImmutableArray.CreateBuilder<EmbedField>(_fields.Count);
for (int i = 0; i < _fields.Count; i++)
fields.Add(_fields[i].Build());
var fields = ImmutableArray.CreateBuilder<EmbedField>(Fields.Count);
for (int i = 0; i < Fields.Count; i++)
fields.Add(Fields[i].Build());
_embed.Fields = fields.ToImmutable(); _embed.Fields = fields.ToImmutable();
return _embed; return _embed;
} }


Loading…
Cancel
Save