Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CloudEventAttribute should implement equality operators

See original GitHub issue

CloudEvent.GetPopulatedAttributes() returns an IEnumerable<KeyValuePair<CloudEventAttribute, object>> which is actually a bit odd. You’d think it would be usable as a dictionary, but I’m guessing there might be a cause where the same attribute names appear more than once, but in my case, I know they won’t, so I tried to create a dictionary from it, but unfortunately, since the Key is CloudEventAttribute, indexing it requires equality operators. Even if I simply search the list of KVPs, it makes it awkward to find an attribute that may or may not exist (SingleOrDefault for example, because default is a KVP with null values), so I think I have to loop on it the old fashioned way.

I find the interface in general to be very awkward, but I think some comparison operators would be helpful, or even a helper method that can grab the attribute and/or value by name. There’s already a method to get the attribute, there’s just no value in it; it’s only the name. Maybe there’s some other incantation I’m not seeing; the documentation on extension attributes is lacking in general.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

jskeetcommented, Aug 15, 2022

Okay. I’ll keep going with the IEqualityComparer PR then. That would allow something like:

Dictionary<CloudEventAttribute, object> dict = new(ce.GetPopulatedAttributes(), CloudEventAttribute.NameComparer);
jskeetcommented, Aug 12, 2022

We could add extension methods for that easily without a new collection type. Anyway, will look more carefully on Monday.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CloudEvents SQL Expression Language
The goal of this specification is to define an expression language SQL-like which can be used to express predicates on CloudEvents instances. Overview....
Read more >
spec/cloudevents/ at main
A CloudEvent MAY include any number of additional context attributes with distinct names, known as "extension attributes". Extension attributes MUST follow the ...
Read more > - cloudevents/sdk-javascript
To augment an already created CloudEvent object, we have added a cloneWith method that takes attributes to add/update. Features. add types to package.json...
Read more >
Class: CloudEvents::Event::V0
This object represents a complete CloudEvent, including the event data and context attributes. It supports the standard required and optional attributes defined ...
Read more >
Using GCP Cloud Functions with F# ...
Excuse the brevity of the function but I just wanted to illustrate the main elements in play here. You'll see that we have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found