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

Implementing nullability annotations on Dapr.Client SDK #1317

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Dapr.Client/BulkPublishEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// limitations under the License.
// ------------------------------------------------------------------------

#nullable enable

using System.Collections.Generic;

namespace Dapr.Client
Expand All @@ -28,7 +30,7 @@ public class BulkPublishEntry<TValue>
/// <param name="eventData">Event to be published.</param>
/// <param name="contentType">Content Type of the event to be published.</param>
/// <param name="metadata">Metadata for the event.</param>
public BulkPublishEntry(string entryId, TValue eventData, string contentType, IReadOnlyDictionary<string, string> metadata = default)
public BulkPublishEntry(string entryId, TValue eventData, string contentType, IReadOnlyDictionary<string, string>? metadata = default)
{
this.EntryId = entryId;
this.EventData = eventData;
Expand All @@ -55,7 +57,7 @@ public BulkPublishEntry(string entryId, TValue eventData, string contentType, IR
/// The metadata set for this particular event.
/// Any particular values in this metadata overrides the request metadata present in BulkPublishRequest.
/// </summary>
public IReadOnlyDictionary<string, string> Metadata { get; }
public IReadOnlyDictionary<string, string>? Metadata { get; }

}
}
8 changes: 5 additions & 3 deletions src/Dapr.Client/BulkStateItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -11,6 +11,8 @@
// limitations under the License.
// ------------------------------------------------------------------------

#nullable enable

namespace Dapr.Client
{
/// <summary>
Expand Down Expand Up @@ -65,7 +67,7 @@ public readonly struct BulkStateItem<TValue>
/// <remarks>
/// Application code should not need to create instances of <see cref="BulkStateItem" />.
/// </remarks>
public BulkStateItem(string key, TValue value, string etag)
public BulkStateItem(string key, TValue? value, string etag)
{
this.Key = key;
this.Value = value;
Expand All @@ -80,7 +82,7 @@ public BulkStateItem(string key, TValue value, string etag)
/// <summary>
/// Gets the deserialized value of the indicated type.
/// </summary>
public TValue Value { get; }
public TValue? Value { get; }

/// <summary>
/// Get the ETag.
Expand Down
10 changes: 6 additions & 4 deletions src/Dapr.Client/CloudEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -11,6 +11,8 @@
// limitations under the License.
// ------------------------------------------------------------------------

#nullable enable

using System;
using System.Text.Json.Serialization;
using Dapr.Client;
Expand All @@ -26,19 +28,19 @@ public class CloudEvent
/// CloudEvent 'source' attribute.
/// </summary>
[JsonPropertyName("source")]
public Uri Source { get; init; }
public Uri? Source { get; init; }

/// <summary>
/// CloudEvent 'type' attribute.
/// </summary>
[JsonPropertyName("type")]
public string Type { get; init; }
public string? Type { get; init; }

/// <summary>
/// CloudEvent 'subject' attribute.
/// </summary>
[JsonPropertyName("subject")]
public string Subject { get; init; }
public string? Subject { get; init; }
}

/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/Dapr.Client/Dapr.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Shared\ArgumentVerifier.cs" />
<Compile Include="..\Shared\DaprDefaults.cs" />
Expand All @@ -13,7 +17,7 @@

<!-- Additional Nuget package properties. -->
<PropertyGroup>
<Description>This package contains the reference assemblies for developing services using Dapr.</Description>
<Description>This package contains the reference assemblies for developing services using Dapr.</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.15.0" />
Expand Down
14 changes: 8 additions & 6 deletions src/Dapr.Client/DaprApiException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -11,6 +11,8 @@
// limitations under the License.
// ------------------------------------------------------------------------

#nullable enable

namespace Dapr
{
using System;
Expand Down Expand Up @@ -55,7 +57,7 @@ public DaprApiException(string message, Exception innerException)
/// </summary>
/// <param name="errorCode">The error code associated with the exception.</param>
/// <param name="isTransient">True, if the exception is to be treated as an transient exception.</param>
public DaprApiException(string errorCode, bool isTransient)
public DaprApiException(string? errorCode, bool isTransient)
: this(string.Empty, errorCode, isTransient)
{
}
Expand All @@ -66,7 +68,7 @@ public DaprApiException(string errorCode, bool isTransient)
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="errorCode">The error code associated with the exception.</param>
/// <param name="isTransient">Indicating if its an transient exception. </param>
public DaprApiException(string message, string errorCode, bool isTransient)
public DaprApiException(string message, string? errorCode, bool isTransient)
: this(message, null, errorCode, isTransient)
{
}
Expand All @@ -80,7 +82,7 @@ public DaprApiException(string message, string errorCode, bool isTransient)
/// <param name="inner">The exception that is the cause of the current exception or null if no inner exception is specified. The <see cref="System.Exception" /> class provides more details about the inner exception..</param>
/// <param name="errorCode">The error code associated with the exception.</param>
/// <param name="isTransient">Indicating if its an transient exception. </param>
public DaprApiException(string message, Exception inner, string errorCode, bool isTransient)
public DaprApiException(string message, Exception? inner, string? errorCode, bool isTransient)
: base(message, inner)
{
this.ErrorCode = errorCode ?? "UNKNOWN";
Expand All @@ -100,7 +102,7 @@ protected DaprApiException(SerializationInfo info, StreamingContext context)
{
if (info != null)
{
this.ErrorCode = (string)info.GetValue(nameof(this.ErrorCode), typeof(string));
this.ErrorCode = info.GetValue(nameof(this.ErrorCode), typeof(string)) as string;
this.IsTransient = info.GetBoolean(nameof(this.IsTransient));
}
}
Expand All @@ -109,7 +111,7 @@ protected DaprApiException(SerializationInfo info, StreamingContext context)
/// Gets the error code parameter.
/// </summary>
/// <value>The error code associated with the <see cref="DaprApiException" /> exception.</value>
public string ErrorCode { get; }
public string? ErrorCode { get; }

/// <summary>
/// Gets a value indicating whether gets exception is Transient and operation can be retried.
Expand Down
Loading
Loading