C
Claire
My main object has been designed for read/write in a property grid.
As I couldn't see a way to make it readonly when I needed to, I created a
2nd skeleton object that exposed the properties of the 1st one as read only.
There's a lot of properties in the objects, and hence a lot of
[Category(""),Description("")] attributes.
Not wanting to duplicate, I added another class containing static strings as
follows
public class strs
{
public static string IDNo = "Point ID number";
public static string ChannelType = "If a measurement point is AC or DC
coupled (as defined in the point's Hardware Settings field) then this field
has no effect";
public static string catTrainName = "Train heirarchy";
............
}
Then I changed my attributes to something similar to the following:
[Category(strs.catHardwareSettings),Description(strs.TriggerRange)]
public SettingsTuple.eTriggerRange TriggerRange
{
get{return Settings.TriggerRange;}
}
Compiler didn't complain at first, as I had to fix other bits of code. It
waited until I'd spent over an hour moving the 100 or so passages of text
(snarl). It complained that it needed const rather than static. So I did did
a search and replace changing static to const and recompiled.
I expected the software to fail when I assigned the SelectedObject property
at runtime but it didn't. What's really bugging me about this, is that the
compiler allowed it, the property grid works and is showing the field
attributes correctly, but I haven't created an instance of the strs class! I
used statics at first because I knew they were always available, but I
didn't expect that consts could be used similarly.
Can someone explain it to me please.
Claire
As I couldn't see a way to make it readonly when I needed to, I created a
2nd skeleton object that exposed the properties of the 1st one as read only.
There's a lot of properties in the objects, and hence a lot of
[Category(""),Description("")] attributes.
Not wanting to duplicate, I added another class containing static strings as
follows
public class strs
{
public static string IDNo = "Point ID number";
public static string ChannelType = "If a measurement point is AC or DC
coupled (as defined in the point's Hardware Settings field) then this field
has no effect";
public static string catTrainName = "Train heirarchy";
............
}
Then I changed my attributes to something similar to the following:
[Category(strs.catHardwareSettings),Description(strs.TriggerRange)]
public SettingsTuple.eTriggerRange TriggerRange
{
get{return Settings.TriggerRange;}
}
Compiler didn't complain at first, as I had to fix other bits of code. It
waited until I'd spent over an hour moving the 100 or so passages of text
(snarl). It complained that it needed const rather than static. So I did did
a search and replace changing static to const and recompiled.
I expected the software to fail when I assigned the SelectedObject property
at runtime but it didn't. What's really bugging me about this, is that the
compiler allowed it, the property grid works and is showing the field
attributes correctly, but I haven't created an instance of the strs class! I
used statics at first because I knew they were always available, but I
didn't expect that consts could be used similarly.
Can someone explain it to me please.
Claire