@@ -45,7 +45,6 @@ internal static class ParameterizedTestDetector
4545
4646 // Build example from current parameter values (resolved from the appropriate object)
4747 var example = BuildExampleFromParameters ( declaringObject ! , parameters ) ;
48- if ( example is null ) return null ;
4948
5049 // Stable ID based on declaring type + method name (shared across invocations)
5150 var declaringType = method . DeclaringType ?? testType ;
@@ -123,26 +122,35 @@ private static bool IsParameterizedTestMethod(MethodInfo method)
123122 foreach ( var param in parameters )
124123 {
125124 var paramName = param . Name ! ;
126- object ? value = ResolveParameterValue ( testObject , type , paramName , bindingFlags ) ;
125+ if ( ! TryResolveParameterValue ( testObject , type , paramName , bindingFlags , out var value ) )
126+ return null ; // Can't resolve all parameters — skip Example creation
127+
127128 values . Add ( new ExampleValue ( paramName , value , ( ) => rowIndex ) ) ;
128129 }
129130
130131 return values . Count > 0 ? new Example ( [ .. values ] ) : null ;
131132 }
132133
133- private static object ? ResolveParameterValue ( object testObject , Type type , string paramName , BindingFlags flags )
134+ private static bool TryResolveParameterValue ( object testObject , Type type , string paramName , BindingFlags flags , out object ? value )
134135 {
135136 // Try field (including backing fields from primary constructors)
136137 var field = FindField ( type , paramName , flags ) ;
137138 if ( field is not null )
138- return field . GetValue ( testObject ) ;
139+ {
140+ value = field . GetValue ( testObject ) ;
141+ return true ;
142+ }
139143
140144 // Try property
141145 var prop = FindProperty ( type , paramName , flags ) ;
142146 if ( prop is not null )
143- return prop . GetValue ( testObject ) ;
147+ {
148+ value = prop . GetValue ( testObject ) ;
149+ return true ;
150+ }
144151
145- return null ;
152+ value = null ;
153+ return false ;
146154 }
147155
148156 private static FieldInfo ? FindField ( Type type , string name , BindingFlags flags )
@@ -159,8 +167,7 @@ private static bool IsParameterizedTestMethod(MethodInfo method)
159167 var fields = type . GetFields ( flags ) ;
160168 foreach ( var f in fields )
161169 {
162- if ( f . Name . Equals ( $ "<{ name } >P", StringComparison . Ordinal ) ||
163- f . Name . Contains ( name , StringComparison . OrdinalIgnoreCase ) )
170+ if ( f . Name . Equals ( $ "<{ name } >P", StringComparison . Ordinal ) )
164171 return f ;
165172 }
166173
@@ -180,10 +187,10 @@ private static bool IsParameterizedTestMethod(MethodInfo method)
180187 }
181188 }
182189
183- internal sealed class ParameterizedTestInfo ( MethodInfo method , string stableScenarioId , Example example )
190+ internal sealed class ParameterizedTestInfo ( MethodInfo method , string stableScenarioId , Example ? example )
184191 {
185192 public MethodInfo Method { get ; } = method ;
186193 public string StableScenarioId { get ; } = stableScenarioId ;
187- public Example Example { get ; } = example ;
194+ public Example ? Example { get ; } = example ;
188195 }
189196}
0 commit comments