convert gradient in to color keys

I am trying to change particle color over lifetime gradient by only using C# code. Is it possible to implement a gradient like this using code, without gradient editor?
The documentation has one made for Blue->Red gradient, But it is difficult to figure out the below gradient with multiple colors.

I don’t know the exact values, but you will get the idea, nothing difficult. Just retrieve the exact colors and times using the inspector, and tweak them in the code if you want.

ParticleSystem ps = GetComponent<ParticleSystem>();
var col = ps.colorOverLifetime;
col.enabled = true;

Gradient gradiend = new Gradient();
GradientColorKey[] colorKeys = new GradientColorKey[3];
GradientAlphaKey[] alphaKeys new GradientAlphaKey[2];

alphaKeys[0].time = 0 ;
alphaKeys[0].alpha = 1;

alphaKeys[1].time = 1 ;
alphaKeys[1].alpha = 1;

colorKeys[0].time = 0.079;
colorKeys[0].color = Color.white;

colorKeys[1].time = 0.15;
colorKeys[1].color = new Color32(R, G, B);

colorKeys[2].time = 0.5;
colorKeys[2].color = new Color32(R, G, B);

gradiend.SetKeys(colorKeys, alphaKeys);        

col.color = grad;