Currently, an Il2CppType is required for specifying a type as a parameter in a Custom Attribute. This has several problems:
Injected classes don't have an Il2CppType.
Getting the Il2CppType can be cumbersome or performance-intensive.
Using a TypeAnalysisContext would be cleaner and more versatile.
Design Proposal
Currently, CustomAttributeTypeParameter is only used in a handful of locations. It should be trivial to add a new derived class of BaseCustomAttributeParameter and update the required locations.
public class InjectedCustomAttributeTypeParameter : BaseCustomAttributeParameter
{
public TypeAnalysisContext? Type { get; }
public InjectedCustomAttributeTypeParameter(TypeAnalysisContext? type, AnalyzedCustomAttribute owner, CustomAttributeParameterKind kind, int index) : base(owner, kind, index)
{
Type = type;
}
}
Alternative Design
We could make a common base class for Custom Attribute type parameters.
public abstract class BaseCustomAttributeTypeParameter : BaseCustomAttributeParameter
{
public BaseCustomAttributeTypeParameter(AnalyzedCustomAttribute owner, CustomAttributeParameterKind kind, int index) : base(owner, kind, index)
{
}
public abstract TypeSignature? ToTypeSignature(ModuleDefinition parentModule);
}
This would allow us to abstract over the origin of the attribute parameter and prevent duplicate code.
Issue
Currently, an
Il2CppType
is required for specifying a type as a parameter in a Custom Attribute. This has several problems:Il2CppType
.Il2CppType
can be cumbersome or performance-intensive.Using a
TypeAnalysisContext
would be cleaner and more versatile.Design Proposal
Currently,
CustomAttributeTypeParameter
is only used in a handful of locations. It should be trivial to add a new derived class ofBaseCustomAttributeParameter
and update the required locations.Alternative Design
We could make a common base class for Custom Attribute type parameters.
This would allow us to abstract over the origin of the attribute parameter and prevent duplicate code.