Skip to content
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

Click Event UrlOffset #31

Open
noteCe opened this issue Jul 5, 2017 · 1 comment
Open

Click Event UrlOffset #31

noteCe opened this issue Jul 5, 2017 · 1 comment

Comments

@noteCe
Copy link

noteCe commented Jul 5, 2017

Hi,
I want to get click event information. Some click event contains urloffset, some is not. (Ex : https://github.com/mirajavora/sendgrid-webhooks/blob/master/Sendgrid.Webhooks.Tests/Events/click.json )
When event doesn't contain UrlOffset, i'm getting ' Object reference not set to an instance of an object' error.
int clickIndex = clickEvent.UrlOffset.Index; string clickType = clickEvent.UrlOffset.Type;

How can i use Contains() method ?
Like following :
if (clickEvent.Contains("UrlOffset")) { }

Thanks.

@andrewchilcott
Copy link

To ensure that you do not get null references, you need to include a null check in a ClickEvent constructor

  public class ClickEvent : EngagementEventBase
   {
       public ClickEvent()
       {
           if (this.UrlOffset == null)
               this.UrlOffset = new UrlOffset();
       }

       [JsonProperty("url")]
       public string Url { get; set; }

       [JsonProperty("url_offset")]
       public UrlOffset UrlOffset { get; set; }
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants