Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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 lessor 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
}

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
}

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
}
added 6 characters in body
Source Link
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
}

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 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
}

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
}
added 515 characters in body
Source Link
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 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
}

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.

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 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
}
Source Link
wondra
  • 4.9k
  • 1
  • 22
  • 36
Loading