Skip to content

Commit 5344aae

Browse files
committed
Use construct
1 parent 4a3d557 commit 5344aae

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/NServiceBus.Core/Features/FeatureFactory.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@ namespace NServiceBus.Features;
55

66
class FeatureFactory
77
{
8-
public virtual Feature CreateFeature(Type featureType)
9-
{
10-
if (!typeof(Feature).IsAssignableFrom(featureType))
11-
{
12-
throw new ArgumentException($"The provided type '{featureType.FullName}' is not a valid feature. All features must inherit from '{typeof(Feature).FullName}'.");
13-
}
14-
15-
return (Feature)Activator.CreateInstance(featureType)!;
16-
}
8+
public virtual Feature CreateFeature(Type featureType) => !typeof(Feature).IsAssignableFrom(featureType)
9+
? throw new ArgumentException(
10+
$"The provided type '{featureType.FullName}' is not a valid feature. All features must inherit from '{typeof(Feature).FullName}'.")
11+
: featureType.Construct<Feature>();
1712
}

0 commit comments

Comments
 (0)