-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify SendGridMessage internal code #406
Comments
I have have a signed contributor agreement ready to send.
This throws NullReferenceException because the Tos collection is not initialized.
This throws ArgumentOutOfRangeException cause this code checks of the index is greater than the count and insert at the point. I think the expression should be personalizationIndex < this.Personalizations.Count (note, avoid using Linq methods when collections have a property) or it should just be an Add() call instead of Insert or it should check the parameters better. Thoughts? |
Hello @pbolduc, For the Regarding the second code example, when you execute |
On the AddTo, it would be possible to have a personalization already initialized but the associated collection Tos / Bccs / Ccs not initialized yet. It could simplify a bunch of things if each of the models that contain collections, that the collections are auto initialized with empty lists. The down side is extra memory is allocated and will need to be garbage collected. Also, during serialization, extra checks would be needed to ensure empty arrays are not serialized. On the second example, you are correct in that I do no have that many items in the collection. Either the API could throw an error (recommended) or append the new personalization at the end of the collection. To me it would make sense to throw an error because caller would expect to be able to get the newly created personalization at message.Personalization[2]. this would throw index out of bounds exception. Tightening up the API will make it easier and less error prone for the users. However, it must be consistent with the other language SDKs. |
How about adding a constructor here that initializes all the minimally required fields. |
Issue Summary
Refactor repeated code out into utility functions. e.g. https://github.com/sendgrid/sendgrid-csharp/blob/master/src/SendGrid/Helpers/Mail/SendGridMessage.cs#L142
The text was updated successfully, but these errors were encountered: