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

Address warnings in sample projects #2849

Merged
merged 1 commit into from
Nov 11, 2024
Merged
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
8 changes: 4 additions & 4 deletions samples/Configuration/HttpFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
}
2 changes: 1 addition & 1 deletion samples/CustomMiddleware/ExceptionHandlingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next
}
}

private OutputBindingData<HttpResponseData> GetHttpOutputBindingFromMultipleOutputBinding(FunctionContext context)
private static OutputBindingData<HttpResponseData>? GetHttpOutputBindingFromMultipleOutputBinding(FunctionContext context)
{
// The output binding entry name will be "$return" only when the function return type is HttpResponseData
var httpOutputBinding = context.GetOutputBindings<HttpResponseData>()
Expand Down
2 changes: 1 addition & 1 deletion samples/CustomMiddleware/HttpFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "g
var logger = context.GetLogger<HttpFunction>();

// 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
2 changes: 1 addition & 1 deletion samples/CustomMiddleware/MyCustomMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyCustomMiddleware>();

Expand Down
7 changes: 4 additions & 3 deletions samples/Extensions/Blob/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
}
6 changes: 3 additions & 3 deletions samples/Extensions/CosmosDB/CosmosDBFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CosmosDBFunction(ILogger<CosmosDBFunction> 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%",
Expand All @@ -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; }

Expand Down
8 changes: 4 additions & 4 deletions samples/Extensions/CosmosDB/CosmosInputBindingFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
}
15 changes: 6 additions & 9 deletions samples/Extensions/EventGrid/EventGridFunction.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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()
{
Expand All @@ -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<string, object> Data { get; set; }
public IDictionary<string, object>? Data { get; set; }
}
}
2 changes: 1 addition & 1 deletion samples/Extensions/MultiOutput/MultiOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class MyOutputType
[QueueOutput("myQueue")]
public string? Name { get; set; }

public HttpResponseData HttpResponse { get; set; }
public HttpResponseData? HttpResponse { get; set; }
}
//</docsnippet_multiple_outputs>
}
8 changes: 4 additions & 4 deletions samples/Extensions/Queue/QueueFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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<string> Songs { get; set; }
public List<string>? Songs { get; set; }
}
}
8 changes: 4 additions & 4 deletions samples/Extensions/SignalR/SignalRFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
6 changes: 3 additions & 3 deletions samples/Extensions/Table/TableFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
2 changes: 1 addition & 1 deletion samples/Extensions/Timer/TimerFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
//</docsnippet_fixed_delay_retry_example>
}
Expand Down