Add SortingLayer by script

hello i need to create dynamically sorting layers by code (C#).
then i can get its ID and give to a sprite.

i need to do this since i have no idea what is the exact number of the sprites, and each sprite HAS to have its own sorting layer

PS: not a normal Layer, but the Sorting Layer

i tried:

SortingLayer sl = new SortingLayer ();
sl.name = "something";
sl.id = 12;

but obviously this does not work.
any help?

@hfiani

Something like this should work (editor only)

SerializedObject tagsAndLayersManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
SerializedProperty sortingLayersProp = tagsAndLayersManager.FindProperty("m_SortingLayers");
sortingLayersProp.InsertArrayElementAtIndex(sortingLayersProp.arraySize);
var newlayer = sortingLayersProp.GetArrayElementAtIndex(sortingLayersProp.arraySize);
newlayer.FindPropertyRelative("uniqueID").intValue = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
newlayer.FindPropertyRelative("name").stringValue = "my new layer";
tagsAndLayersManager.ApplyModifiedProperties();

no one knows the answer to this question? i searched a lot but found nothing

https://stackoverflow.com/questions/49270205/how-to-add-sorting-layer-via-script/49270639#49270639?newreg=b5385c3543c84dc7be686c6cfc194564

here’s an appropriate and functional answer, if anyone is still out there searching