473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1091
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Michele Simionato | last post by:
So far, I have not installed Prothon, nor I have experience with Io, Self or other prototype-based languages. Still, from the discussion on the mailing list, I have got the strong impression that...
9
by: Jay | last post by:
Everywhere I go (read/browse) I see these parameters.... ByVal sender As Object, ByVal e As System.EventArgs Yet I never see them used within the function/method. Could someone tell me what they...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
16
by: John Doe | last post by:
Hi, I wrote a small class to enumerate available networks on a smartphone : class CNetwork { public: CNetwork() {}; CNetwork(CString& netName, GUID netguid): _netname(netName),...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.