-
Notifications
You must be signed in to change notification settings - Fork 582
Open
Labels
status: help wantedrequesting help from the communityrequesting help from the communitytype: community enhancementfeature request not on Twilio's roadmapfeature request not on Twilio's roadmap
Description
Issue Summary
AddCategories use provided list as a reference
so any further add's impact on first provided collection
Steps to Reproduce
- Create a SendGridMessage
- Create a static List with 1 category (or provide it via
IOptions<>
as normal ppl do) - Add that list to message using
AddCategories
- Add other category (using
AddCategories
orAddCategory
) - See that list from the static field is bigger
- See that list from point 2 is bigger
- Send email (success)
- Retry steps 1-6
- Send email (failed, because there are duplicated category,)
Code Snippet
Your AddCategories looks like:
public void AddCategories(List<string> categories)
{
if (Categories == null)
{
Categories = new List<string>();
Categories = categories;
}
else
{
Categories.AddRange(categories);
}
}
but it should be more like:
public void AddCategories(List<string> categories)
{
if (Categories == null)
{
Categories = new HashSet<string>(categories); // First change type to HashSet to prevent duplications
}
else
{
foreach (var item in categories) // It need to be like that because this is no longer List but HashSet to prevent duplication
Categories.Add(categories);
}
}
or at least change to be like:
public void AddCategories(List<string> categories)
{
if (Categories == null)
{
Categories = categories.ToList();
}
else
{
Categories.AddRange(categories);
}
}
Technical details:
- sendgrid-csharp version:
9.25.2.0 (newest)
- csharp version:
.netstandard 2.0
Metadata
Metadata
Assignees
Labels
status: help wantedrequesting help from the communityrequesting help from the communitytype: community enhancementfeature request not on Twilio's roadmapfeature request not on Twilio's roadmap