Marking property as dirty in property drawer after changing its objectReferenceValue

I’ve got an attribute that restricts a serialized field to be of a certain type. It works well, except for one problem. When I use this attribute on a prefab’s serialized field and change it from outside the prefab editor, the property never gets dirtied.

property.objectReferenceValue = 
EditorGUI.ObjectField(position, label, property.objectReferenceValue, type);

I can’t use EditorGUI.PropertyField(position, property, label);, since there’s nothing I can use to enforce the type of the property.

I want a way to dirty the property when it changes object its objectReferenceValue

I needed to wrap my assignment with BeginProperty and EndProperty calls

EditorGUI.BeginProperty(position, GUIContent.none, property);
property.objectReferenceValue = 
    EditorGUI.ObjectField(position, label, property.objectReferenceValue, type);
EditorGUI.EndProperty();