Skip to main content
3 of 4
added 6 characters in body
wondra
  • 4.9k
  • 1
  • 22
  • 36

You can access and change attributes using reflection, something like:

var attrs = (RangeAttribute[])typeof(myScript).GetCustomAttributes (typeof(RangeAttribute), false);
attrs [0].max = 10;

should work - more or less.
Question is, why would you even wanted that? The only point of Range attribute I see is changing textbox to slider in designer (or is there something more to it?). In case you dont need to access the field in editor you could use properties instead, it even gives you more flexibility(you can define "overflow" logic):

[Range(1, 10)]
public int multiplier;
public int _x;
public int X {
  get { return _x; }
  set { _x = Math.Min(10 * multiplier, value); } //clamp for example
}
wondra
  • 4.9k
  • 1
  • 22
  • 36