mercredi 8 juin 2022

Is it possible to get the position in code of e.g. MemberInfo?

The question

Is there a way to get the position in code of where an attribute has been used, or the location where a member variable has been declared?

I am not searching for a workaround for this problem, only for a simple answer if this is technically possible or not.

Some background information

I have defined an attribute that connects a member to a VisualElement in a Unity UI Document using the parameters provided to the Attribute. Here's an example:

[Query("button-upvote")]
private Button _buttonUpvote;

Now in some situations the element does not exist, which means _buttonUpvote cannot be resolved, maybe because there is a typo, in which case I want to log a warning to the Unity console. In this warning I get a stack trace, but I don't get a stack trace that leads me to the attribute or the member in question as in the above example, it leads me to the code that logged the warning, which is totally unrelated to the actual error in this case. I would like to include the position where the Query attribute has been used, in the warning log.





Aucun commentaire:

Enregistrer un commentaire