You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, instantiated new triggers with the C# isolate model will produce code like the following:
usingSystem.IO;usingSystem.Threading.Tasks;usingMicrosoft.Azure.Functions.Worker;usingMicrosoft.Extensions.Logging;namespaceCompany.Function{publicclassBlobTriggerCSharp{privatereadonlyILogger<BlobTriggerCSharp>_logger;publicBlobTriggerCSharp(ILogger<BlobTriggerCSharp>logger){_logger=logger;}[Function(nameof(BlobTriggerCSharp))]publicasyncTaskRun([BlobTrigger("PathValue/{name}",Connection="ConnectionValue")]Streamstream,stringname){usingvarblobStreamReader=newStreamReader(stream);varcontent=awaitblobStreamReader.ReadToEndAsync();_logger.LogInformation($"C# Blob trigger function Processed blob\n Name: {name}\n Data: {content}");}}}
If possible, this code would benefit from using the new primary constructors feature in C# 12:
usingSystem.IO;usingSystem.Threading.Tasks;usingMicrosoft.Azure.Functions.Worker;usingMicrosoft.Extensions.Logging;namespaceCompany.Function{publicclassBlobTriggerCSharp(ILogger<BlobTriggerCSharp>logger){[Function(nameof(BlobTriggerCSharp))]publicasyncTaskRun([BlobTrigger("PathValue/{name}",Connection="ConnectionValue")]Streamstream,stringname){usingvarblobStreamReader=newStreamReader(stream);varcontent=awaitblobStreamReader.ReadToEndAsync();logger.LogInformation($"C# Blob trigger function Processed blob\n Name: {name}\n Data: {content}");}}}
We could potentially reduce more nesting and code by using file-scoped namespaces as well to further reduce it to:
usingSystem.IO;usingSystem.Threading.Tasks;usingMicrosoft.Azure.Functions.Worker;usingMicrosoft.Extensions.Logging;namespaceCompany.Function;publicclassBlobTriggerCSharp(ILogger<BlobTriggerCSharp>logger){[Function(nameof(BlobTriggerCSharp))]publicasyncTaskRun([BlobTrigger("PathValue/{name}",Connection="ConnectionValue")]Streamstream,stringname){usingvarblobStreamReader=newStreamReader(stream);varcontent=awaitblobStreamReader.ReadToEndAsync();logger.LogInformation($"C# Blob trigger function Processed blob\n Name: {name}\n Data: {content}");}}
The text was updated successfully, but these errors were encountered:
captainsafia
changed the title
Consider using C# primary constructors for generated trigger code
Consider using modern C# features for generated triggers
Oct 8, 2024
Currently, instantiated new triggers with the C# isolate model will produce code like the following:
If possible, this code would benefit from using the new primary constructors feature in C# 12:
We could potentially reduce more nesting and code by using file-scoped namespaces as well to further reduce it to:
The text was updated successfully, but these errors were encountered: