Let's say we want to do something, which is not possible via generic method. The easiest example - return created instances for each found type, and those types have constructors with parameters.
Currently you have to resort to using Activator (which is not compile safe).
public BaseType[] GetTypeInstances(string argument)
{
return [
new TypeA(argument),
new TypeB(argument)
];
}
I suggest to parameter HandlerTemplate to ScanForTypesAttribute. Source generator should replace T with full name of found type:
[ScanForTypes(AssignableTo=typeof(BaseType), HanderTemplate = "new T(argument)")]
public partial BaseType[] GetTypeInstances(string argument);
It should support void methods (or methods returning first argument) as well:
[ScanForTypes(AssignableTo=typeof(BaseType), HanderTemplate = "registry.Add(new T(argument))")]
public partial void GetTypeInstances(BaseTypeRegistry registry, string argument);
For this case I suggest to add ';' to the end of the string if it is not there.
It is not supported to have both Handler and HandlerTemplate.
Let's say we want to do something, which is not possible via generic method. The easiest example - return created instances for each found type, and those types have constructors with parameters.
Currently you have to resort to using Activator (which is not compile safe).
I suggest to parameter HandlerTemplate to ScanForTypesAttribute. Source generator should replace
Twith full name of found type:It should support void methods (or methods returning first argument) as well:
For this case I suggest to add ';' to the end of the string if it is not there.
It is not supported to have both
HandlerandHandlerTemplate.