Skip to content

Commit f25ffe4

Browse files
committed
Enable nullable ref type annotations in InvocationTypeGenerator
1 parent e80c1f5 commit f25ffe4

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

src/Castle.Core/DynamicProxy/Generators/InvocationTypeGenerator.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#nullable enable
16+
1517
namespace Castle.DynamicProxy.Generators
1618
{
1719
using System;
@@ -96,7 +98,7 @@ protected virtual MethodInvocationExpression GetCallbackMethodInvocation(ClassEm
9698
return contributor.GetCallbackMethodInvocation(invocation, args, targetField, invokeMethodOnTarget);
9799
}
98100
var methodOnTargetInvocationExpression = new MethodInvocationExpression(
99-
new AsTypeExpression(targetField, callbackMethod.DeclaringType),
101+
new AsTypeExpression(targetField, callbackMethod.DeclaringType!),
100102
callbackMethod,
101103
args) { VirtualCall = true };
102104
return methodOnTargetInvocationExpression;
@@ -124,7 +126,7 @@ protected virtual void ImplementInvokeMethodOnTarget(ClassEmitter invocation, Pa
124126

125127
var methodOnTargetInvocationExpression = GetCallbackMethodInvocation(invocation, args, callbackMethod, targetField, invokeMethodOnTarget);
126128

127-
LocalReference returnValue = null;
129+
LocalReference? returnValue = null;
128130
if (callbackMethod.ReturnType != typeof(void))
129131
{
130132
var returnType = invocation.GetClosedParameterType(callbackMethod.ReturnType);
@@ -145,7 +147,7 @@ protected virtual void ImplementInvokeMethodOnTarget(ClassEmitter invocation, Pa
145147

146148
if (callbackMethod.ReturnType != typeof(void))
147149
{
148-
argumentsMarshaller.SetReturnValue(returnValue);
150+
argumentsMarshaller.SetReturnValue(returnValue!);
149151
}
150152

151153
invokeMethodOnTarget.CodeBuilder.AddStatement(ReturnStatement.Instance);
@@ -178,7 +180,7 @@ private void EmitCallThrowOnNoTarget(MethodEmitter invokeMethodOnTarget)
178180
invokeMethodOnTarget.CodeBuilder.AddStatement(ReturnStatement.Instance);
179181
}
180182

181-
private MethodInfo GetCallbackMethod(ClassEmitter invocation)
183+
private MethodInfo? GetCallbackMethod(ClassEmitter invocation)
182184
{
183185
if (contributor != null)
184186
{
@@ -200,7 +202,7 @@ private MethodInfo GetCallbackMethod(ClassEmitter invocation)
200202

201203
private ClassEmitter GetEmitter(ClassEmitter @class, Type[] interfaces, INamingScope namingScope, MethodInfo methodInfo)
202204
{
203-
var suggestedName = string.Format("Castle.Proxies.Invocations.{0}_{1}", methodInfo.DeclaringType.Name,
205+
var suggestedName = string.Format("Castle.Proxies.Invocations.{0}_{1}", methodInfo.DeclaringType!.Name,
204206
methodInfo.Name);
205207
var uniqueName = namingScope.ParentScope.GetUniqueName(suggestedName);
206208
return new ClassEmitter(@class.ModuleScope, uniqueName, GetBaseType(), interfaces, ClassEmitter.DefaultTypeAttributes, forceUnsigned: @class.InStrongNamedModule == false);
@@ -232,7 +234,7 @@ private void ImplementChangeProxyTarget(ClassEmitter invocation, ClassEmitter @c
232234
new AssignStatement(localProxy,
233235
new ConvertExpression(localProxy.Type, proxyObject)));
234236

235-
var dynSetProxy = typeof(IProxyTargetAccessor).GetMethod(nameof(IProxyTargetAccessor.DynProxySetTarget));
237+
var dynSetProxy = typeof(IProxyTargetAccessor).GetMethod(nameof(IProxyTargetAccessor.DynProxySetTarget))!;
236238

237239
changeProxyTarget.CodeBuilder.AddStatement(
238240
new MethodInvocationExpression(localProxy, dynSetProxy, changeProxyTarget.Arguments[0])
@@ -264,7 +266,7 @@ public ArgumentsMarshaller(ClassEmitter invocation, MethodEmitter method, Parame
264266
this.parameters = parameters;
265267
}
266268

267-
public void CopyOut(out IExpression[] arguments, out LocalReference[] byRefArguments, out bool hasByRefArguments)
269+
public void CopyOut(out IExpression[] arguments, out LocalReference?[] byRefArguments, out bool hasByRefArguments)
268270
{
269271
if (parameters.Length == 0)
270272
{
@@ -275,13 +277,13 @@ public void CopyOut(out IExpression[] arguments, out LocalReference[] byRefArgum
275277
}
276278

277279
arguments = new IExpression[parameters.Length];
278-
byRefArguments = new LocalReference[parameters.Length];
280+
byRefArguments = new LocalReference?[parameters.Length];
279281
hasByRefArguments = false;
280282

281283
for (int i = 0, n = parameters.Length; i < n; ++i)
282284
{
283285
var argumentType = invocation.GetClosedParameterType(parameters[i].ParameterType);
284-
var dereferencedArgumentType = argumentType.IsByRef ? argumentType.GetElementType() : argumentType;
286+
var dereferencedArgumentType = argumentType.IsByRef ? argumentType.GetElementType()! : argumentType;
285287

286288
IExpression dereferencedArgument;
287289

@@ -321,7 +323,7 @@ public void CopyOut(out IExpression[] arguments, out LocalReference[] byRefArgum
321323
}
322324
}
323325

324-
public void CopyIn(LocalReference[] byRefArguments)
326+
public void CopyIn(LocalReference?[] byRefArguments)
325327
{
326328
for (int i = 0, n = byRefArguments.Length; i < n; ++i)
327329
{

0 commit comments

Comments
 (0)