Work out with ISerializationCallbackReceiver if MonoBehaviour is on Prefab or not?

I’m currently trying to work out on save if a MonoBehaviour being serialised is a prefab or not, here’s an example of what I’m trying to do:

public class Sync : MonoBehaviour, ISerializationCallbackReceiver
{
    [SerializedField] private bool m_isPrefab;

    void ISerializationCallbackReceiver.OnBeforeSerialize()
    {
#if UNITY_EDITOR
        if (!UnityEditor.EditorApplication.isPlaying)
        {
            m_isPrefab = UnityEditor.SceneManagement.EditorSceneManager.IsPreviewScene(gameObject.scene) ||
                    UnityEditor.PrefabUtility.IsPartOfPrefabAsset(this) ||
                    (UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage()?.IsPartOfPrefabContents(gameObject) ?? false);
        }
#endif
    }

    void ISerializationCallbackReceiver.OnAfterDeserialize()
    {
    }
}

But right not this doesn’t work on saving the asset, it saves them outside the preview scene so that returns false and when saving it seems to not be flagged as part of a Prefab asset.

Is this the intended behaviour?
Any one have ideas on how to check this?

Has to be somewhat light as it could be on many objects at once

Never mind I fixed this pretty quickly after posting (the usual with coding)

m_isPrefab = UnityEditor.SceneManagement.EditorSceneManager.IsPreviewScene(gameObject.scene) ||
                        UnityEditor.PrefabUtility.IsPartOfPrefabAsset(this) || !gameObject.scene.IsValid()

When saving the asset, the prefab isn’t in any scene, so the scene isn’t valid, add that and it seems to be working quite well