Generalized casting in generated code

  • Thread starter Thread starter Vadim Berman
  • Start date Start date
V

Vadim Berman

Hello group,

I am working on a component that has a generic Control reference. In design
time, I create it on the fly (that is, it is not linked directly to the
form) internally.

When I set its properties, and these properties are specific to the control
type (i.e. "Checked" for CheckBox, "Multiline" for TextBox, etc.), the code
is generated, but the compilation fails, since these properties don't belong
to the base Control class. For example, assignment like this:

Me.SettingCtrlData1.Control.Location = New System.Drawing.Point(40, 0)
succeeds while

Me.SettingCtrlData1.Control.Checked = True

fails. Obviously, the correct code would be:

CType(Me.SettingCtrlData1.Control, CheckBox).Checked = True

The question is, how do I achieve this. TypeConverter stuff wouldn't work
here, I guess. Or would it?



Vadim Berman
www.Power-Components.NET
 
I assume you're using CodeDOM: look for the CodeCastExpression type...
(System.CodeDom.CodeCastExpression)

HTH
 
Back
Top