How to get access to the class you where decorating with Property drawer?

How to get access to the class (instance of the class) you where decorating with Property drawer?

I the script below, I want to call the method “Test()” from the PropertyDrawer script. Is it possible?

using UnityEngine;
using UnityEditor;

[System.Serializable]
public class MyClass
{
	public string name;
	
	public void Test() => Debug.Log(name);
}

[CustomPropertyDrawer(typeof(MyClass))]
public class MyClassPropertyDrawer : PropertyDrawer
{
	MyClass script;
	
	void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
	{
		if(!script)
			script = (MyClass) target; // just an example, like the way we do with "Editor"
		
		script?.Test();
	}
}

Maybe I’m getting it wrong but, as you are defining a new variable of type MyClass, you don’t need to pair it with the script itself -as you say- “like the way we do with Editor”. You can use it straightforward:

[CustomPropertyDrawer(typeof(MyClass))]
public class MyClassPropertyDrawer : PropertyDrawer
{
    MyClass script;
    void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
    {
        script.Test();
    }
}

Even though I imagine you already tried this…