stiletto icon indicating copy to clipboard operation
stiletto copied to clipboard

User-created Qualifier attributes

Open benjamin-bader opened this issue 12 years ago • 2 comments

NamedAttribute is privileged at this point; Keys knows what it is and how to accommodate it. This was done initially to make implementing Stiletto less complicated, but Now is the Right Time to add generalized qualifiers.

For example, instead of [Inject, Named("listen-port")], you could have [Inject, ListenPort]

declared like so:

[AttributeUsage(AttributeTargets.Property|AttributeTargets.Parameter|AttributeTargets.Method)]
public class ListenPortAttribute : QualifierAttribute {}

benjamin-bader avatar Jul 27 '13 00:07 benjamin-bader

Stumbling block: how to handle ctor parameters and properties consistently between fody and runtime? This works in Java because annotations don't have executable code.

Can we create a string repr based on consistently-ordered fields and properties? It works in the compiled form, maybe, but how to access that at runtime without instantiating the attribute (thus allowing arbitrary code to run)?

benjamin-bader avatar Aug 06 '13 01:08 benjamin-bader

Potential solution: CustomAttributeData.GetCustomAttributes in ReflectionOnly context; this gives us the raw ctor argumentes as stored in metadata. Can we do this on an assembly that's already loaded in execution context?

...goddamnit, that API doesn't exist in Silverlight!

benjamin-bader avatar Aug 06 '13 01:08 benjamin-bader