A
Andy Bell
Can this be done via .net generics? How? The % signs below are just to show
how I want to do it, I realise they're not valid syntax.
public abstract class BaseSelectionRequirement {
...
protected Type mControlType;
protected string mFieldName;
protected Type mFieldType;
protected UserControl mControl;
...
public %mFieldType% Value {
get {
return ( ( %mControlType% ) mControl ).%mFieldName%;
}
set {
( ( %mControlType% ) mControl ).%mFieldName% = value;
}
}
}
So, say my descended class was:
public class HatSelectionRequirement : BaseSelectionRequirement {
public HatSelectionRequirement( ) {
mControlType = HatUserControl;
mFieldType = typeof( Int32 );
mFieldName = "Size";
}
...
}
Then I could get/set the int HatUserControl.Size via
HatSelectionRequirement.Value
how I want to do it, I realise they're not valid syntax.
public abstract class BaseSelectionRequirement {
...
protected Type mControlType;
protected string mFieldName;
protected Type mFieldType;
protected UserControl mControl;
...
public %mFieldType% Value {
get {
return ( ( %mControlType% ) mControl ).%mFieldName%;
}
set {
( ( %mControlType% ) mControl ).%mFieldName% = value;
}
}
}
So, say my descended class was:
public class HatSelectionRequirement : BaseSelectionRequirement {
public HatSelectionRequirement( ) {
mControlType = HatUserControl;
mFieldType = typeof( Int32 );
mFieldName = "Size";
}
...
}
Then I could get/set the int HatUserControl.Size via
HatSelectionRequirement.Value