Skip to content

Commit 4611de8

Browse files
committed
1 parent d92b7bb commit 4611de8

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/Processors/Constructor/ConstructorDiagnostic.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ public override IEnumerable<object> Select(Type type, IPolicySet registration)
144144
return new[] { SelectMethod(type, constructors) };
145145
}
146146

147-
148147
#endregion
149148

150149

src/Processors/Constructor/ConstructorProcessor.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,34 @@ private bool CanResolve(Type type)
207207
#else
208208
var info = type;
209209
#endif
210-
211210
if (info.IsClass)
212211
{
213-
if (DelegateType.IsAssignableFrom(info) ||
214-
typeof(string) == type || info.IsEnum || info.IsPrimitive || info.IsAbstract)
215-
{
216-
return _isTypeRegistered(type);
217-
}
218-
212+
// Array could be either registered or Type can be resolved
219213
if (type.IsArray)
220214
{
221215
return _isTypeRegistered(type) || CanResolve(type.GetElementType());
222216
}
223217

218+
// Type must be registered if:
219+
// - String
220+
// - Enumeration
221+
// - Primitive
222+
// - Abstract
223+
// - Interface
224+
// - No accessible constructor
225+
if (DelegateType.IsAssignableFrom(info) ||
226+
typeof(string) == type || info.IsEnum || info.IsPrimitive || info.IsAbstract
227+
#if NETSTANDARD1_0 || NETCOREAPP1_0
228+
|| !info.DeclaredConstructors.Any(c => !c.IsFamily && !c.IsPrivate))
229+
#else
230+
|| !type.GetTypeInfo().DeclaredConstructors.Any(c => !c.IsFamily && !c.IsPrivate))
231+
#endif
232+
return _isTypeRegistered(type);
233+
224234
return true;
225235
}
226236

237+
// Can resolve if IEnumerable or factory is registered
227238
if (info.IsGenericType)
228239
{
229240
var genericType = type.GetGenericTypeDefinition();
@@ -234,6 +245,7 @@ private bool CanResolve(Type type)
234245
}
235246
}
236247

248+
// Check if Type is registered
237249
return _isTypeRegistered(type);
238250
}
239251

0 commit comments

Comments
 (0)