mrpmorris / Morris.Moxy

Moxy - Mixins code generator for C#
MIT License
111 stars 6 forks source link

RFC: Reflection #27

Open mrpmorris opened 1 year ago

mrpmorris commented 1 year ago

At the moment, Moxy will only re-generate source for a mix-in decorated class if

  1. The class's signature changes
  2. The contents of the .mixin file changes

Adding/removing members does inside a C# class does not trigger a regeneration of its mix-ins, this is to enhance performance.

I want to be able to provide additional information to a mix-in about the class that it is working on. For example, it would be nice to be able to see the names of the class's properties, or only properties that are decorated with [Required] - but I don't want to start triggering source regeneration every time the coder alters their code on a property / method / field if there are no mix-ins that care.

So, I'm considering supporting some kind of query definition in the header of a .mixin

@moxy
@reflect someData = ( want the names of all properties decorated with MinLength, and the Length value of that attribute)
@moxy

{{ for datum in someData }} Property {{ datum.Name }} has a min length of {{ datum.Length }} {{ end }}

This will allow me to convert the reflect selection to json which gives two benefits

  1. The values can be made available inside the Scriban template
  2. I will only need to regenerate the source code for the mix-in whenever the json changes

RFC

I'd like suggestions for what the query text format might look like.

Any ideas appreciated!

mrpmorris commented 1 year ago

I think I might just make it simple

@moxy
@reflect properties, methods, fields
@moxy

Where options would be

(public | non-public)? (static | instance)? (properties | methods | fields)

e.g.

properties = public instance properties
non-public properties = instance properties that are not public
public static methods = methods that are static and public