Grab a Component by Type within a Job

I’m trying to build a Stat - Affect system. My first attempt was a unique system, component, and affect buffer for each stat, but it smelled like a bad design. So, I thought maybe I could use a single dynamic buffer of affects where each affect holds a reference to whichever stat component it should modify. I’m unsure if there’s a proper way to do something akin to the code below, or if it’s a bad idea:

public struct Health : IComponentData
{
    public int Value;
    public int MaxValue;
}

// unknown number of other stats with same fields

public struct StatAffect : IBufferElementData
{
    public Type TargetComponent;
    public int Value;
    public int Iterations;
    public float Delay;
    public float Time;
}

public class StatAffectSystem : SystemBase
{
    protected override void OnUpdate ()
    {
        // [NativeDisableParallelForRestriction]  
        Entities.ForEach( (Entity entity, DynamicBuffer<StatAffect> statAffectBuffer) => {
           
            foreach (var statAffect in statAffectBuffer)
            {
                // get some Entity component using statAffect.TargetComponent
                // logic to modify component
                // write to component with updated values
            }
        })
        .ScheduleParallel();
    }
}

You would have to hardcode an enum for each component type to get this to work. Separate jobs seems like a better solution.

What I dislike about separate jobs is each one would have the same logic, the only difference being a component and buffer type. Could I build a single job with a generics that I could reuse? This may have been covered in another forum thread, but the search feature isn’t working today.

Can you show code of what this looks like with two jobs and two types?

This does not answer your question, but maybe it will help you to accomplish your goal.
In my stat system, I dont have separate component type for each stat. I only have buffer with stats, each stat having its exclusive index, ie. Health has index 3 in stat buffer. When applying effect i dont have to switch stat type, i just directly access it by index.
This have its own flaws, like each entity with stats has the buffer element for each possible stat which can be wastefull. Also the stat value scale (int vs. floats) must be same for each stat.