diff --git a/src/CloudNative.CloudEvents/CloudEvent.cs b/src/CloudNative.CloudEvents/CloudEvent.cs
index bd149f1..fa669c1 100644
--- a/src/CloudNative.CloudEvents/CloudEvent.cs
+++ b/src/CloudNative.CloudEvents/CloudEvent.cs
@@ -71,8 +71,13 @@ namespace CloudNative.CloudEvents
/// CloudEvents specification version
/// Extensions to be added to this CloudEvents
public CloudEvent(CloudEventsSpecVersion specVersion, IEnumerable extensions)
+ : this(new CloudEventAttributes(specVersion, extensions), extensions)
{
- attributes = new CloudEventAttributes(specVersion, extensions);
+ }
+
+ private CloudEvent(CloudEventAttributes attributes, IEnumerable extensions)
+ {
+ this.attributes = attributes;
var extensionMap = new Dictionary();
if (extensions != null)
{
@@ -155,11 +160,11 @@ namespace CloudNative.CloudEvents
/// specification which the event uses. This enables the interpretation of the context.
///
///
- public CloudEventsSpecVersion SpecVersion
- {
- get => attributes.SpecVersion;
- set => attributes.SpecVersion = value;
- }
+ public CloudEventsSpecVersion SpecVersion => attributes.SpecVersion;
+
+ // TODO: Consider exposing publicly.
+ internal CloudEvent WithSpecVersion(CloudEventsSpecVersion newSpecVersion) =>
+ new CloudEvent(attributes.WithSpecVersion(newSpecVersion), Extensions.Values);
///
/// CloudEvents 'subject' attribute. This describes the subject of the event in the context
diff --git a/src/CloudNative.CloudEvents/CloudEventAttributes.cs b/src/CloudNative.CloudEvents/CloudEventAttributes.cs
index 57266a3..01462ea 100644
--- a/src/CloudNative.CloudEvents/CloudEventAttributes.cs
+++ b/src/CloudNative.CloudEvents/CloudEventAttributes.cs
@@ -14,6 +14,19 @@ namespace CloudNative.CloudEvents
///
public class CloudEventAttributes : IDictionary
{
+ private static readonly List> attributeNameMethods = new List>
+ {
+ DataAttributeName,
+ DataContentTypeAttributeName,
+ DataSchemaAttributeName,
+ IdAttributeName,
+ SourceAttributeName,
+ SpecVersionAttributeName,
+ SubjectAttributeName,
+ TimeAttributeName,
+ TypeAttributeName,
+ };
+
readonly CloudEventsSpecVersion specVersion;
IDictionary dict = new Dictionary(StringComparer.InvariantCultureIgnoreCase);
@@ -24,8 +37,7 @@ namespace CloudNative.CloudEvents
{
this.extensions = extensions;
this.specVersion = specVersion;
- dict[SpecVersionAttributeName(specVersion)] = (specVersion == CloudEventsSpecVersion.V0_1 ? "0.1" :
- (specVersion == CloudEventsSpecVersion.V0_2 ? "0.2" : (specVersion == CloudEventsSpecVersion.V0_3 ? "0.3" : "1.0")));
+ dict[SpecVersionAttributeName(specVersion)] = SpecVersionString(specVersion);
}
int ICollection>.Count => dict.Count;
@@ -36,100 +48,44 @@ namespace CloudNative.CloudEvents
ICollection