From 6236ab784c0c343f56e54920f3de52735a0749a3 Mon Sep 17 00:00:00 2001 From: Jacob Viau Date: Mon, 11 Nov 2024 13:59:07 -0800 Subject: [PATCH] Address warnings in sample projects --- samples/Configuration/HttpFunction.cs | 8 ++++---- .../ExceptionHandlingMiddleware.cs | 2 +- samples/CustomMiddleware/HttpFunction.cs | 2 +- .../HttpTriggerWithMultipleOutputBindings.cs | 4 ++-- samples/CustomMiddleware/MyCustomMiddleware.cs | 2 +- samples/Extensions/Blob/Book.cs | 7 ++++--- samples/Extensions/CosmosDB/CosmosDBFunction.cs | 6 +++--- .../CosmosDB/CosmosInputBindingFunctions.cs | 8 ++++---- samples/Extensions/EventGrid/EventGridFunction.cs | 15 ++++++--------- samples/Extensions/MultiOutput/MultiOutput.cs | 2 +- samples/Extensions/Queue/QueueFunction.cs | 8 ++++---- samples/Extensions/SignalR/SignalRFunction.cs | 8 ++++---- samples/Extensions/Table/TableFunction.cs | 6 +++--- samples/Extensions/Timer/TimerFunction.cs | 2 +- 14 files changed, 39 insertions(+), 41 deletions(-) diff --git a/samples/Configuration/HttpFunction.cs b/samples/Configuration/HttpFunction.cs index 5129cee25..4e3d8424f 100644 --- a/samples/Configuration/HttpFunction.cs +++ b/samples/Configuration/HttpFunction.cs @@ -25,15 +25,15 @@ public static MyType Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post public class MyType { - public string camelCasePropertyName { get; set; } - public string PascalCasePropertyName { get; set; } - public string NullValue { get; set; } + public string? camelCasePropertyName { get; set; } + public string? PascalCasePropertyName { get; set; } + public string? NullValue { get; set; } // This sample can use both System.Text.Json and Newtonsoft.Json, depending on which // is registered. Including both attributes here. [JsonPropertyName("Changed_Via_System_Text_Json")] [JsonProperty("Changed_Via_Newtonsoft_Json")] - public string DifferentSerializedName { get; set; } + public string? DifferentSerializedName { get; set; } } } } diff --git a/samples/CustomMiddleware/ExceptionHandlingMiddleware.cs b/samples/CustomMiddleware/ExceptionHandlingMiddleware.cs index 003c78905..d16a96191 100644 --- a/samples/CustomMiddleware/ExceptionHandlingMiddleware.cs +++ b/samples/CustomMiddleware/ExceptionHandlingMiddleware.cs @@ -60,7 +60,7 @@ public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next } } - private OutputBindingData GetHttpOutputBindingFromMultipleOutputBinding(FunctionContext context) + private static OutputBindingData? GetHttpOutputBindingFromMultipleOutputBinding(FunctionContext context) { // The output binding entry name will be "$return" only when the function return type is HttpResponseData var httpOutputBinding = context.GetOutputBindings() diff --git a/samples/CustomMiddleware/HttpFunction.cs b/samples/CustomMiddleware/HttpFunction.cs index ed7f19949..5d1c9a363 100644 --- a/samples/CustomMiddleware/HttpFunction.cs +++ b/samples/CustomMiddleware/HttpFunction.cs @@ -23,7 +23,7 @@ public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "g var logger = context.GetLogger(); // Get the item set by the middleware - if (context.Items.TryGetValue("middlewareitem", out object value) && value is string message) + if (context.Items.TryGetValue("middlewareitem", out object? value) && value is string message) { logger.LogInformation("From middleware: {message}", message); } diff --git a/samples/CustomMiddleware/HttpTriggerWithMultipleOutputBindings.cs b/samples/CustomMiddleware/HttpTriggerWithMultipleOutputBindings.cs index ea2e8e4ec..9645d38af 100644 --- a/samples/CustomMiddleware/HttpTriggerWithMultipleOutputBindings.cs +++ b/samples/CustomMiddleware/HttpTriggerWithMultipleOutputBindings.cs @@ -32,8 +32,8 @@ public static MyOutputType Run([HttpTrigger(AuthorizationLevel.Anonymous, "get") public class MyOutputType { [QueueOutput("functionstesting2", Connection = "AzureWebJobsStorage")] - public string Name { get; set; } + public string? Name { get; set; } - public HttpResponseData HttpResponse { get; set; } + public HttpResponseData? HttpResponse { get; set; } } } diff --git a/samples/CustomMiddleware/MyCustomMiddleware.cs b/samples/CustomMiddleware/MyCustomMiddleware.cs index 48c61a5bc..ffc5c58e1 100644 --- a/samples/CustomMiddleware/MyCustomMiddleware.cs +++ b/samples/CustomMiddleware/MyCustomMiddleware.cs @@ -20,7 +20,7 @@ public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next // This happens after function execution. We can inspect the context after the function // was invoked - if (context.Items.TryGetValue("functionitem", out object value) && value is string message) + if (context.Items.TryGetValue("functionitem", out object? value) && value is string message) { ILogger logger = context.GetLogger(); diff --git a/samples/Extensions/Blob/Book.cs b/samples/Extensions/Blob/Book.cs index 824e88336..383645748 100644 --- a/samples/Extensions/Blob/Book.cs +++ b/samples/Extensions/Blob/Book.cs @@ -5,7 +5,8 @@ namespace SampleApp { public class Book { - public string Id { get; set; } - public string Name { get; set; } + public string? Id { get; set; } + + public string? Name { get; set; } } -} \ No newline at end of file +} diff --git a/samples/Extensions/CosmosDB/CosmosDBFunction.cs b/samples/Extensions/CosmosDB/CosmosDBFunction.cs index d2b044aa2..17a2ec7e0 100644 --- a/samples/Extensions/CosmosDB/CosmosDBFunction.cs +++ b/samples/Extensions/CosmosDB/CosmosDBFunction.cs @@ -21,7 +21,7 @@ public CosmosDBFunction(ILogger logger) [Function(nameof(CosmosDBFunction))] [ExponentialBackoffRetry(5, "00:00:04", "00:15:00")] [CosmosDBOutput("%CosmosDb%", "%CosmosContainerOut%", Connection = "CosmosDBConnection", CreateIfNotExists = true)] - public object Run( + public object? Run( [CosmosDBTrigger( "%CosmosDb%", "%CosmosContainerIn%", @@ -48,9 +48,9 @@ public object Run( public class MyDocument { - public string Id { get; set; } + public string? Id { get; set; } - public string Text { get; set; } + public string? Text { get; set; } public int Number { get; set; } diff --git a/samples/Extensions/CosmosDB/CosmosInputBindingFunctions.cs b/samples/Extensions/CosmosDB/CosmosInputBindingFunctions.cs index 41d0317a4..62955cd8a 100644 --- a/samples/Extensions/CosmosDB/CosmosInputBindingFunctions.cs +++ b/samples/Extensions/CosmosDB/CosmosInputBindingFunctions.cs @@ -265,15 +265,15 @@ public void DocByIdFromJSON( public class ToDoItem { - public string Id { get; set; } - public string Description { get; set; } + public string? Id { get; set; } + public string? Description { get; set; } } public class ToDoItemLookup { - public string ToDoItemId { get; set; } + public string? ToDoItemId { get; set; } - public string ToDoItemPartitionKeyValue { get; set; } + public string? ToDoItemPartitionKeyValue { get; set; } } } } diff --git a/samples/Extensions/EventGrid/EventGridFunction.cs b/samples/Extensions/EventGrid/EventGridFunction.cs index aa1b6e004..18b1342ba 100644 --- a/samples/Extensions/EventGrid/EventGridFunction.cs +++ b/samples/Extensions/EventGrid/EventGridFunction.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -using System; -using System.Collections.Generic; using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging; @@ -15,8 +13,7 @@ public static class EventGridFunction public static MyEventType Run([EventGridTrigger] MyEventType input, FunctionContext context) { var logger = context.GetLogger(nameof(EventGridFunction)); - - logger.LogInformation(input.Data.ToString()); + logger.LogInformation(input.Data?.ToString()); var outputEvent = new MyEventType() { @@ -34,16 +31,16 @@ public static MyEventType Run([EventGridTrigger] MyEventType input, FunctionCont public class MyEventType { - public string Id { get; set; } + public string? Id { get; set; } - public string Topic { get; set; } + public string? Topic { get; set; } - public string Subject { get; set; } + public string? Subject { get; set; } - public string EventType { get; set; } + public string? EventType { get; set; } public DateTime EventTime { get; set; } - public IDictionary Data { get; set; } + public IDictionary? Data { get; set; } } } diff --git a/samples/Extensions/MultiOutput/MultiOutput.cs b/samples/Extensions/MultiOutput/MultiOutput.cs index 025ec85ab..e56700a48 100644 --- a/samples/Extensions/MultiOutput/MultiOutput.cs +++ b/samples/Extensions/MultiOutput/MultiOutput.cs @@ -38,7 +38,7 @@ public class MyOutputType [QueueOutput("myQueue")] public string? Name { get; set; } - public HttpResponseData HttpResponse { get; set; } + public HttpResponseData? HttpResponse { get; set; } } // } diff --git a/samples/Extensions/Queue/QueueFunction.cs b/samples/Extensions/Queue/QueueFunction.cs index b9f821c58..cfa26b8b7 100644 --- a/samples/Extensions/Queue/QueueFunction.cs +++ b/samples/Extensions/Queue/QueueFunction.cs @@ -28,7 +28,7 @@ public string[] Run([QueueTrigger("input-queue")] Album myQueueItem, FunctionCon // Use a string array to return more than one message. string[] messages = { $"Album name = {myQueueItem.Name}", - $"Album songs = {myQueueItem.Songs.ToString()}"}; + $"Album songs = {myQueueItem.Songs}"}; _logger.LogInformation("{msg1},{msg2}", messages[0], messages[1]); @@ -58,10 +58,10 @@ public void QueueBinaryDataFunction([QueueTrigger("input-queue")] BinaryData mes public class Album { - public string Id { get; set; } + public string? Id { get; set; } - public string Name { get; set; } + public string? Name { get; set; } - public List Songs { get; set; } + public List? Songs { get; set; } } } diff --git a/samples/Extensions/SignalR/SignalRFunction.cs b/samples/Extensions/SignalR/SignalRFunction.cs index b567e7928..ace3ea3e6 100644 --- a/samples/Extensions/SignalR/SignalRFunction.cs +++ b/samples/Extensions/SignalR/SignalRFunction.cs @@ -33,15 +33,15 @@ public static class SignalRFunction public class MyConnectionInfo { - public string Url { get; set; } + public string? Url { get; set; } - public string AccessToken { get; set; } + public string? AccessToken { get; set; } } public class MyMessage { - public string Target { get; set; } + public string? Target { get; set; } - public object[] Arguments { get; set; } + public object[]? Arguments { get; set; } } } diff --git a/samples/Extensions/Table/TableFunction.cs b/samples/Extensions/Table/TableFunction.cs index 95894ed68..9936538ef 100644 --- a/samples/Extensions/Table/TableFunction.cs +++ b/samples/Extensions/Table/TableFunction.cs @@ -102,10 +102,10 @@ public void TablePocoFunction( public class MyTableData { - public string PartitionKey { get; set; } + public string? PartitionKey { get; set; } - public string RowKey { get; set; } + public string? RowKey { get; set; } - public string Text { get; set; } + public string? Text { get; set; } } } diff --git a/samples/Extensions/Timer/TimerFunction.cs b/samples/Extensions/Timer/TimerFunction.cs index e94913097..1b0d405ca 100644 --- a/samples/Extensions/Timer/TimerFunction.cs +++ b/samples/Extensions/Timer/TimerFunction.cs @@ -15,7 +15,7 @@ public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo timerInfo, FunctionContext context) { var logger = context.GetLogger(nameof(TimerFunction)); - logger.LogInformation($"Function Ran. Next timer schedule = {timerInfo.ScheduleStatus.Next}"); + logger.LogInformation($"Function Ran. Next timer schedule = {timerInfo.ScheduleStatus?.Next}"); } // }