473,394 Members | 1,715 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,394 software developers and data experts.

C# Class Library: multiple classes

I have a class library which contains 3 classes; one exposes all its
behaviours and the other two are used internally by the public class. My
problem is that although I can create an instance of the subservient classes,
I cannot see the methods in them from the public class.

Could someone guide me on this or give me a template?
Thanks.
Oct 4 '07 #1
6 3650
On Oct 4, 8:29 am, AA2e72E <AA2e...@discussions.microsoft.comwrote:
I have a class library which contains 3 classes; one exposes all its
behaviours and the other two are used internally by the public class. My
problem is that although I can create an instance of the subservient classes,
I cannot see the methods in them from the public class.

Could someone guide me on this or give me a template?
Thanks.
Sounds like the methods in the subservient classes are defined as
Private. To see them from the primary class in the class library, they
will need to be either Public or Friend.

Oct 4 '07 #2
On Oct 4, 1:29 pm, AA2e72E <AA2e...@discussions.microsoft.comwrote:
I have a class library which contains 3 classes; one exposes all its
behaviours and the other two are used internally by the public class. My
problem is that although I can create an instance of the subservient classes,
I cannot see the methods in them from the public class.

Could someone guide me on this or give me a template?
The two subservient classes should be declared as "internal", and any
method you want to use from other classes in the same assembly should
also be declared as "internal".

Jon

Oct 4 '07 #3
Jon, I think I am still missing something. Here's the gist of the code ...
please lookout for the comments for the questions I have. Thank you very much
for your help.

The function below is the <publicclass.

public string TargetDB
{
get { return xTargetDB; }
set
{
xTargetDB = value.ToUpper();
switch (xTargetDB)
{
case "ORACLE":
{
TDB = new ORACLE();
break;
}
default:
{
TDB = new SQLSERVER();
break;
}
}
}
}

public string xyz()
{

// I expected test() to be exposed below but it isn't

return TDB.ToString() ; // I used ToString() just to have the
project compile

// I want to be able to run this statement: return TDB.test() ;
// HOW?
}

ORACLE and SQLSERVER are the subservient classes:

this is ORACLE.CS

sing System;
using System.Collections.Generic;
using System.Text;

namespace ACM
{
internal class ORACLE
{
internal string test()
{
return "Oracle";
}
}
}

this is SQLSERVER.CS

using System;
using System.Collections.Generic;
using System.Text;

namespace ACM
{
internal class SQLSERVER
{
internal string test()
{
return "SQLServer";
}
}
}
I am using a WindowsApplication to test the class library:

namespace ACMTESTER
{
public partial class Form1 : Form
{
Main CI = new ACM.Main();
public Form1()
{
InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)
{

}
private void button1_Click(object sender, EventArgs e)
{
CI.TargetDB = "ORACLE";
MessageBox.Show(CI.xyz());
}
}

Oct 4 '07 #4
On Oct 4, 3:28 pm, AA2e72E <AA2e...@discussions.microsoft.comwrote:
Jon, I think I am still missing something. Here's the gist of the code ...
"The gist of the code" isn't terribly helpful, unfortunately. We've no
idea what TDB is, for instance - a field, a property? What's its
scope?

You've got a problem in that your SQLSERVER and ORACLE classes (it
would be good to start complying with naming conventions by the way) -
they don't implement a common interface. You should define an
interface containing the test() method, and make both classes
implement that interface. TDB should be declared to be of that
interface type, at which point your problems are likely to go away.
I'm guessing that TDB is currently declared as type object - but
unfortunately I can only guess at the moment.

Jon

Oct 4 '07 #5
Yes, TDB is declared as object.
I tried

ORACLE TDB = new ORACLE();

and SQLSERVER TDB = new SQLSERVER();

but could not get test() exposed.

Thanks for the quidance; I'll work on the 'common interface'.
Oct 4 '07 #6
On Oct 4, 4:01 pm, AA2e72E <AA2e...@discussions.microsoft.comwrote:
Yes, TDB is declared as object.
I tried

ORACLE TDB = new ORACLE();

and SQLSERVER TDB = new SQLSERVER();

but could not get test() exposed.
Either of those would have worked in terms of exposing the test()
method, but then your TargetDB property's setter would fail, as you
wouldn't be able to assign an ORACLE reference to a variable of type
SQLSERVER or vice versa.
Thanks for the quidance; I'll work on the 'common interface'.
Righto. If you have any more problems, please post a short but
*complete* program demonstrating them. See http://pobox.com/~skeet/csharp/complete.html

Jon

Oct 4 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: syd | last post by:
In my project, I've got dozens of similar classes with hundreds of description variables in each. In my illustrative example below, I have a Library class that contains a list of Nation classes. ...
1
by: ik | last post by:
Hello All, Please point me to the right news group if this is not the right one. I have to store c++ class hierarchy, in some structure. From that structure, I need to query for the baseclasses....
3
by: David Lozzi | last post by:
Howdy, I've discovered how to create and use a class in ASP.NET. However, when is the best time to use a class? For example, I am currently using session variables to store user information (user...
3
by: convert a Class Library to web service | last post by:
can i convert a Class Library to be share in the internet as a web service i what thet all my classes in the Class Library will be shared
3
by: eBob.com | last post by:
I have several applications which mine web sites for personal information which they publish. They publish the info in one form, I transform the info into Excel spreadsheets. So all these...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
5
by: Sanjay | last post by:
Hi all, I am new to python. Sorry if this is too novice question, but I could not find an answer yet. While coding a business class library, I think it is preferable to have one class per...
12
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me...
4
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one...
44
by: Steven D'Aprano | last post by:
I have a class which is not intended to be instantiated. Instead of using the class to creating an instance and then operate on it, I use the class directly, with classmethods. Essentially, the...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.