Create callback in a open generic type

I’m trying to have some singleton scriptable objects but I don’t want to have to add the createAssetMenu to every singleton to only be used once and bloat so I wanted to automate it.

This is the code I ended up with:

public class SingletonScriptableObject<T> : ScriptableObject where T : SingletonScriptableObject<T> 
{
    private static T instance;
    public static T Instance
    {
        get 
        { 
            if(instance == null)
            {
                T[] assets = Resources.LoadAll<T>("");
                if(assets == null || assets.Length < 1)
                {
                    throw new System.Exception("Could not find any singleton scriptable object instances in the resources!");
                }
                else if(assets.Length > 1)
                {
                    Debug.LogWarning(assets.Length + " instances of the singleton scriptable object found in cesources, using this", assets[0]);
                    instance = assets[0];
                }
            }
            return instance;
        }
    }

#if UNITY_EDITOR
    [UnityEditor.Callbacks.DidReloadScripts]
    public static void GenerateSingletons()
    {
        string path = "Assets/Resources/Singletons/";

        Debug.Log(typeof(T));

        if (Instance != null) { return; }

        if (typeof(T).IsSubclassOf(typeof(SingletonScriptableObject<T>)))
        {
            System.IO.Directory.CreateDirectory(Application.dataPath + "/" + path);

            var a = ScriptableObject.CreateInstance(instance.GetType().Name);

            AssetDatabase.Refresh();

            AssetDatabase.CreateAsset(a, path + a.name);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = a;
        }
    }
#endif
}

It has one problem, when scripts are reloaded the following error shows up:

Method ‘AutogenerateSingleton1:GenerateSingletons ()' cannot be used for [DidReloadScripts] callback because class 'AutogenerateSingleton1’ is an open generic type.

So i tried to fix it with an interface and moved part of the code to it:

public class SingletonScriptableObject<T> : ScriptableObject where T : SingletonScriptableObject<T> 
{
    protected static T instance;
    public static T Instance // same get as before
}

the new interface:

interface AutogenerateSingleton <T> where T : SingletonScriptableObject<T>
{
    protected static T instance;

    public static T Instance;

#if UNITY_EDITOR
    [UnityEditor.Callbacks.DidReloadScripts]
    public static void GenerateSingletons()
    {
        string path = "Assets/Resources/Singletons/";

        Debug.Log(typeof(T));

        if (Instance != null) { return; }

        if (typeof(T).IsSubclassOf(typeof(SingletonScriptableObject<T>)))
        {
            System.IO.Directory.CreateDirectory(Application.dataPath + "/" + path);

            var a = ScriptableObject.CreateInstance(instance.GetType().Name);

            AssetDatabase.Refresh();

            AssetDatabase.CreateAsset(a, path + a.name);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = a;
        }
    }
#endif
}

And an example of the implementation:

public class ExampleOfImplementation : SingletonScriptableObject<ExampleOfImplementation>, AutogenerateSingleton<ExampleOfImplementation>
{
    public int[] someData;
}

But still the same problem appears:

Method ‘AutogenerateSingleton1:GenerateSingletons ()' cannot be used for [DidReloadScripts] callback because class 'AutogenerateSingleton1’ is an open generic type.

I really would like to get this to work but i’ve run out of ideas.