public override bool CanCreate(Type type, string referenceName, LinkedList<object> buildChain)
{
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
if (type.IsClass &&
type.IsAbstract)
{
// This is an abstract class so we can't create it
return false;
}
if (IsReadOnlyType(type) == false)
{
return false;
}
var internalType = FindEnumerableTypeArgument(type);
if (internalType == null)
{
// The type does not implement IEnumerable<T>
return false;
}
if (type.IsInterface)
{
var listGenericType = typeof(List<string>).GetGenericTypeDefinition();
var listType = listGenericType.MakeGenericType(internalType);
if (type.IsAssignableFrom(listType))
{
// The instance is assignable from List<T> and therefore can be both created and populated by this type creator
return true;
}
return false;
}
// This is a class that we can presumably create so we need to check if it can be populated
if (CanPopulate(type, referenceName, buildChain) == false)
{
// There is no point trying to create something that we can't populate
return false;
}
return true;
}