471,325 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

What happens if class is not available?

I have "MyProject.Commons.frmMessageBox"

if I wanna create it, doing this,

using (MyProject.Commons.frmMessageBox xFrm = new
MyProject.Commons.frmMessageBox())
{
xFrm.ShowDialog();
}

if I do not know "MyProject.Commons.frmMessageBox" is available or not and
want to handle this situation like this

if (Available("MyProject.Commons.frmMessageBox"))
{
ShowCustomDialog("MyProject.Commons.frmMessageBox" );
}

This is possible ?
Jul 30 '08 #1
5 1042
Why would it not be available? If it not referenced by your project, you will
get a compiler error and visual studio, you will get a compiler warning.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Diego Armando Maradona" wrote:
I have "MyProject.Commons.frmMessageBox"

if I wanna create it, doing this,

using (MyProject.Commons.frmMessageBox xFrm = new
MyProject.Commons.frmMessageBox())
{
xFrm.ShowDialog();
}

if I do not know "MyProject.Commons.frmMessageBox" is available or not and
want to handle this situation like this

if (Available("MyProject.Commons.frmMessageBox"))
{
ShowCustomDialog("MyProject.Commons.frmMessageBox" );
}

This is possible ?
Jul 30 '08 #2
Yes, you could probably do something funky with reflection and exception
handling to do this. However I agree with the above poster, if you're trying
to do this you've probably made an incorrect design decision somewhere else.

"Diego Armando Maradona" wrote:
I have "MyProject.Commons.frmMessageBox"

if I wanna create it, doing this,

using (MyProject.Commons.frmMessageBox xFrm = new
MyProject.Commons.frmMessageBox())
{
xFrm.ShowDialog();
}

if I do not know "MyProject.Commons.frmMessageBox" is available or not and
want to handle this situation like this

if (Available("MyProject.Commons.frmMessageBox"))
{
ShowCustomDialog("MyProject.Commons.frmMessageBox" );
}

This is possible ?
Jul 30 '08 #3
Ciaran O''Donnell wrote:
Why would it not be available? If it not referenced by your project, you will
get a compiler error and visual studio, you will get a compiler warning.
An assembly containing the referenced class could be replaced later (at
runtime) - just guessing: maybe .NET will display an 'Open File' Dialog
in this case and friendly ask the user to locate a file which contains
the class "MyProject.Commons.frmMessageBox" ...

Error messages are so medieval ;-)

Best Regards
--
Michael Justin
SCJP, SCJA
betasoft - Software for Delphi™ and for the Java™ platform
http://www.mikejustin.com - http://www.betabeans.de
Jul 30 '08 #4
The runtime will through an error if the assembly containing the type has
been replaced with a version that doesnt contain it. There is sadly no nice
OpenFileDialog.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Michael Justin" wrote:
Ciaran O''Donnell wrote:
Why would it not be available? If it not referenced by your project, you will
get a compiler error and visual studio, you will get a compiler warning.

An assembly containing the referenced class could be replaced later (at
runtime) - just guessing: maybe .NET will display an 'Open File' Dialog
in this case and friendly ask the user to locate a file which contains
the class "MyProject.Commons.frmMessageBox" ...

Error messages are so medieval ;-)

Best Regards
--
Michael Justin
SCJP, SCJA
betasoft - Software for Delphi™ and for the Java™ platform
http://www.mikejustin.com - http://www.betabeans.de
Jul 30 '08 #5
Diego Armando Maradona wrote:
I have "MyProject.Commons.frmMessageBox"

if I wanna create it, doing this,

using (MyProject.Commons.frmMessageBox xFrm = new
MyProject.Commons.frmMessageBox())
{
xFrm.ShowDialog();
}

if I do not know "MyProject.Commons.frmMessageBox" is available or not
and want to handle this situation like this

if (Available("MyProject.Commons.frmMessageBox"))
{
ShowCustomDialog("MyProject.Commons.frmMessageBox" );
}

This is possible ?
I think what you want in this case is a plugin architecture with a
default fallback that just shows a normal messagebox.
You would have to load the assembly dynamically if it exists.
Google c# plugin and you should see how you could do it.

JB
Aug 1 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.