Show compilation error if value is not set

  • Thread starter Thread starter Jack Wright
  • Start date Start date
J

Jack Wright

Dear All,
I have a property UIName, that I want all Application programmers
to set when coding using classes derived from my class (UIName is a
property of my class), how do I give compliation errors...rather than
compile the code and during execution throw an exeception...
Please help...

TALIA
Many regards
Jack
 
Hey Jack,

You can force any derived classes to implement a property or method by
marking the property/method and the base class with the "abstract" keyword.

HTH, Jakob.
 
Thanks Jakob,
I did not put it rightly...

I have a TextBox class that has a property UIName...when a programmer
drag drop this control on his form...I want to force the programmer to
set the UIName for that control...else give him compilation error...How
do I do that? Please help...

TALIA
Many regards
Jack
 
Hey Jack,

I am afraid that you can not do that. But maybe there is some way that you
can set this property yourself to a valid default value when somebody uses
your control?

Regards, Jakob.
 
I was looking out for something like this...

[DefaultValue(null), Nullable(false)]
public string UIName
{
get{return _innerBaseControl.DefaultValue;}
set{_innerBaseControl.DefaultValue=value;}
}

Some attribute tag...is something like this available in .net 2.0
 
This can not be done. How would the compiler know what a property is set to?
Remember, that users of your control are free to set the properties of a
control runtime as well as design-time.

Regards, Jakob.
 
If I set
string myName = 23;

it will give me an error...similarly every property know what data type
it should accept...for a string property I cannot assign a number...in
the DesignView if the User assigns a number it will be converted to
string...
All I want is that the property should not be null or empty...just like
in Database tables...MS should give a thought to this...
Also it would be nice if class programmers are able to define extra
compliation logic to prevent runtime errors and show compliation
errors...

I hope it makes sense...:-)

Thanks Jakob

Many regards
Jack
 
Back
Top