Skip to content

Commit 1906644

Browse files
authored
fixing nullable warnings (#104)
1 parent 805f78d commit 1906644

29 files changed

+140
-88
lines changed

src/DotNetWorker/Context/DefaultFunctionExecutionContext.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
@@ -20,9 +20,9 @@ internal class DefaultFunctionExecutionContext : FunctionExecutionContext, IDisp
2020
public DefaultFunctionExecutionContext(IServiceScopeFactory serviceScopeFactory, FunctionInvocation invocation,
2121
FunctionDefinition definition)
2222
{
23-
_serviceScopeFactory = serviceScopeFactory;
24-
Invocation = invocation;
25-
FunctionDefinition = definition;
23+
_serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
24+
Invocation = invocation ?? throw new ArgumentNullException(nameof(invocation));
25+
FunctionDefinition = definition ?? throw new ArgumentNullException(nameof(definition));
2626
OutputBindings = new Dictionary<string, object>();
2727
}
2828

@@ -32,7 +32,7 @@ public DefaultFunctionExecutionContext(IServiceScopeFactory serviceScopeFactory,
3232

3333
public override object? InvocationResult { get; set; }
3434

35-
public override InvocationLogger Logger { get; set; }
35+
public override InvocationLogger? Logger { get; set; }
3636

3737
public override IDictionary<string, object> OutputBindings { get; }
3838

@@ -42,19 +42,16 @@ public override IServiceProvider InstanceServices
4242
{
4343
get
4444
{
45-
if (_instanceServicesScope == null && _serviceScopeFactory != null)
45+
if (_instanceServicesScope == null)
4646
{
4747
_instanceServicesScope = _serviceScopeFactory.CreateScope();
4848
_instanceServices = _instanceServicesScope.ServiceProvider;
4949
}
5050

51-
return _instanceServices;
51+
return _instanceServices!;
5252
}
5353

54-
set
55-
{
56-
_instanceServices = value;
57-
}
54+
set => _instanceServices = value;
5855
}
5956

6057
public virtual void Dispose()

src/DotNetWorker/Context/FunctionExecutionContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
@@ -18,7 +18,7 @@ public abstract class FunctionExecutionContext
1818

1919
public abstract object? InvocationResult { get; set; }
2020

21-
public abstract InvocationLogger Logger { get; set; }
21+
public abstract InvocationLogger? Logger { get; set; }
2222

2323
// TODO: Double-check previous projects for layout of FunctionInvocation, Bindings, etc
2424
public abstract IDictionary<string, object> OutputBindings { get; }

src/DotNetWorker/Converters/Converter/ConverterContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using Microsoft.Azure.Functions.Worker.Definition;
@@ -10,7 +10,7 @@ internal abstract class ConverterContext
1010
{
1111
public abstract FunctionParameter Parameter { get; set; }
1212

13-
public abstract object Source { get; set; }
13+
public abstract object? Source { get; set; }
1414

1515
public abstract FunctionExecutionContext ExecutionContext { get; set; }
1616
}

src/DotNetWorker/Converters/Converter/DefaultConverterContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using Microsoft.Azure.Functions.Worker.Definition;

src/DotNetWorker/Converters/ExactMatchConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
namespace Microsoft.Azure.Functions.Worker.Converters
@@ -7,7 +7,7 @@ internal class ExactMatchConverter : IConverter
77
{
88
public bool TryConvert(ConverterContext context, out object? target)
99
{
10-
if (context.Source.GetType() == context.Parameter.Type)
10+
if (context.Source?.GetType() == context.Parameter.Type)
1111
{
1212
target = context.Source;
1313
return true;
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
@@ -9,22 +9,23 @@ namespace Microsoft.Azure.Functions.Worker
99
internal class DefaultOutputBinding<T> : OutputBinding<T>
1010
{
1111
private readonly FunctionParameter _param;
12-
private readonly IDictionary<string, object> _outputBindings;
12+
private readonly IDictionary<string, object?> _outputBindings;
1313

14-
public DefaultOutputBinding(FunctionParameter param, IDictionary<string, object> outputBindings)
14+
public DefaultOutputBinding(FunctionParameter param, IDictionary<string, object?> outputBindings)
1515
{
1616
_param = param;
1717
_outputBindings = outputBindings;
1818
}
1919

20-
public override void SetValue(T value)
20+
public override void SetValue(T? value)
2121
{
2222
_outputBindings[_param.Name] = value;
2323
}
2424

25-
internal override T GetValue()
25+
internal override T? GetValue()
2626
{
27-
return (T)_outputBindings[_param.Name];
27+
var value = _outputBindings[_param.Name];
28+
return (T)value;
2829
}
2930
}
3031
}

src/DotNetWorker/Definition/DefaultFunctionDefinitionFactory.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
@@ -54,9 +54,16 @@ public FunctionDefinition Create(FunctionLoadRequest request)
5454

5555
MethodInfo? methodInfo = functionType?.GetMethod(methodName);
5656

57+
if (methodInfo == null)
58+
{
59+
throw new InvalidOperationException($"Method '{methodName}' specified in {nameof(FunctionMetadata.EntryPoint)} was not found. This function cannot be created.");
60+
}
61+
5762
IFunctionInvoker invoker = _functionInvokerFactory.Create(methodInfo);
5863

59-
IEnumerable<FunctionParameter> parameters = methodInfo.GetParameters().Select(p => new FunctionParameter(p.Name, p.ParameterType));
64+
IEnumerable<FunctionParameter> parameters = methodInfo.GetParameters()
65+
.Where(p => p.Name != null)
66+
.Select(p => new FunctionParameter(p.Name!, p.ParameterType));
6067

6168
return new DefaultFunctionDefinition(metadata, invoker, parameters);
6269
}
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System.Collections.Immutable;
5-
using System.Reflection;
6-
74
namespace Microsoft.Azure.Functions.Worker
85
{
9-
public class FunctionMetadata
6+
public abstract class FunctionMetadata
107
{
11-
public string? PathToAssembly { get; set; }
12-
13-
public string? EntryPoint { get; set; }
8+
public abstract string PathToAssembly { get; set; }
149

15-
public string? TypeName { get; set; }
10+
public abstract string EntryPoint { get; set; }
1611

17-
public string? FunctionId { get; set; }
12+
public abstract string FunctionId { get; set; }
1813

19-
public string? FuncName { get; set; }
14+
public abstract string Name { get; set; }
2015
}
2116
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.IO;
5+
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;
6+
7+
namespace Microsoft.Azure.Functions.Worker.Definition
8+
{
9+
internal class GrpcFunctionMetadata : FunctionMetadata
10+
{
11+
public GrpcFunctionMetadata(FunctionLoadRequest loadRequest)
12+
{
13+
EntryPoint = loadRequest.Metadata.EntryPoint;
14+
Name = loadRequest.Metadata.Name;
15+
PathToAssembly = Path.GetFullPath(loadRequest.Metadata.ScriptFile);
16+
FunctionId = loadRequest.FunctionId;
17+
}
18+
19+
public override string PathToAssembly { get; set; }
20+
21+
public override string EntryPoint { get; set; }
22+
23+
public override string FunctionId { get; set; }
24+
25+
public override string Name { get; set; }
26+
}
27+
}

src/DotNetWorker/IFunctionActivator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;

0 commit comments

Comments
 (0)