Skip to content

Commit 9d52bb5

Browse files
committed
Fix S1066: merge collapsible if statements.
1 parent bb88ad9 commit 9d52bb5

2 files changed

Lines changed: 19 additions & 25 deletions

File tree

src/Autofac/Core/Resolving/Middleware/CircularDependencyDetectorMiddleware.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ public void Execute(ResolveRequestContext context, Action<ResolveRequestContext>
4949

5050
var activationDepth = context.Operation.RequestDepth;
5151

52-
if (activationDepth > _maxResolveDepth)
53-
{
5452
#if NETSTANDARD2_1
55-
// In .NET Standard 2.1 we will try and keep going until we run out of stack space.
56-
if (!RuntimeHelpers.TryEnsureSufficientExecutionStack())
57-
{
58-
throw new DependencyResolutionException(string.Format(CultureInfo.CurrentCulture, CircularDependencyDetectorMessages.MaxDepthExceeded, context.Service));
59-
}
53+
// In .NET Standard 2.1 we will try and keep going until we run out of stack space.
54+
if (activationDepth > _maxResolveDepth && !RuntimeHelpers.TryEnsureSufficientExecutionStack())
55+
{
56+
throw new DependencyResolutionException(string.Format(CultureInfo.CurrentCulture, CircularDependencyDetectorMessages.MaxDepthExceeded, context.Service));
57+
}
6058
#else
61-
// Pre .NET Standard 2.1 we just end at 50.
59+
// Pre .NET Standard 2.1 we just end at 50.
60+
if (activationDepth > _maxResolveDepth)
61+
{
6262
throw new DependencyResolutionException(string.Format(CultureInfo.CurrentCulture, CircularDependencyDetectorMessages.MaxDepthExceeded, context.Service));
63-
#endif
6463
}
64+
#endif
6565

6666
var requestStack = dependencyTrackingResolveOperation.RequestStack;
6767

src/Autofac/Util/InternalTypeExtensions.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,25 @@ public static bool IsCompatibleWithGenericParameterConstraints(this Type generic
8080
var specialConstraints = genericArg.GenericParameterAttributes;
8181

8282
if ((specialConstraints & GenericParameterAttributes.DefaultConstructorConstraint)
83-
!= GenericParameterAttributes.None)
83+
!= GenericParameterAttributes.None &&
84+
!parameter.IsValueType && parameter.GetDeclaredPublicConstructors().All(c => c.GetParameters().Length > 0))
8485
{
85-
if (!parameter.IsValueType && parameter.GetDeclaredPublicConstructors().All(c => c.GetParameters().Length > 0))
86-
{
87-
return false;
88-
}
86+
return false;
8987
}
9088

9189
if ((specialConstraints & GenericParameterAttributes.ReferenceTypeConstraint)
92-
!= GenericParameterAttributes.None)
90+
!= GenericParameterAttributes.None &&
91+
parameter.IsValueType)
9392
{
94-
if (parameter.IsValueType)
95-
{
96-
return false;
97-
}
93+
return false;
9894
}
9995

10096
if ((specialConstraints & GenericParameterAttributes.NotNullableValueTypeConstraint)
101-
!= GenericParameterAttributes.None)
97+
!= GenericParameterAttributes.None &&
98+
(!parameter.IsValueType ||
99+
(parameter.IsGenericType && IsGenericTypeDefinedBy(parameter, typeof(Nullable<>)))))
102100
{
103-
if (!parameter.IsValueType ||
104-
(parameter.IsGenericType && IsGenericTypeDefinedBy(parameter, typeof(Nullable<>))))
105-
{
106-
return false;
107-
}
101+
return false;
108102
}
109103
}
110104

0 commit comments

Comments
 (0)