Is there a way to pass instance values to a custom PropertyAttribute?

I have a custom property attribute that lets callers mark a field as read-only.

I’m able to set it up such that it accepts a boolean parameter as to whether or not to to actually make the field readonly, but what I want to do is pass in the value of one of another property as that argument.

Example:

bool CanEditCount = true;

[ReadOnly(!CanEditCount)]
int Count = 0;

This doesn’t appear to work. The compiler gives me an error saying the parameter must be static.

Is there any way I can drive this readonly attribute at the instance level?

No, not really. PropertyAttributes are compile-time, so anything passed to them must be static or const. Here’s the best I can recommend, but it’s a bit hacky:

Make the argument a String. If that string is not null, it ought to be the name of a boolean variable. Then, you can use System.Reflection and typeof() to get the Type, and get the value of the boolean by name in your editor script. But, you’ll want to make sure it doesn’t run in play mode, because that is totally not optimization friendly.