Preventing constants from being hard coded

  • Thread starter Thread starter Thorsten Tarrach
  • Start date Start date
T

Thorsten Tarrach

Hallo,
When I reference to an assembly and use a constant from that assembly it
will be card coded during compilation.
Dim a as integer = test123.class1.myconst 'myconst is 3
becomes to
dim a as integer = 3

For me as the developer of the library causes this behaviour some problemes:
Whenever I change a constant I loose backward compatibility. This also
applies to enums which makes this problem even worse.

Is there an attribute to tell the compiler to get the constants during
runtime?

Thanks, Thorsten
 
I suspect that you could resolve this by using a static variable rather than
a constant.

-ken
 
Thorsten said:
Hallo,
When I reference to an assembly and use a constant from that assembly it
will be card coded during compilation.
Dim a as integer = test123.class1.myconst 'myconst is 3
becomes to
dim a as integer = 3

For me as the developer of the library causes this behaviour some problemes:
Whenever I change a constant I loose backward compatibility. This also
applies to enums which makes this problem even worse.

Is there an attribute to tell the compiler to get the constants during
runtime?

Define test123.Class1.myconst to be a "readonly static" value ("ReadOnly
Shared" in VB.NET)
 
Thanks, that's in fact a good idea, but what about the enums?
If I delete one item, the whole enum gets mixed up.
 
Try using

Public Enum myEnum
Item1 = 1
Item2 = 2
End Enum

Whenever you remove one, the ones that are left over will not change values.
 
Back
Top