How can I do this?

Hi, I have an abstract class, and some inheritant classes, in order for the abstract class methods implementation (these methods make sql operations) to work I need to idenfity from which class the method is beign called.
Doing it this way could save a lot of code (instead of implementing an interface in each class)
Is this possible?, is there any other way to make this?
[383 byte] By [Edgar] at [2007-12-16]
# 1
Is this what you mean?
public abstract DataLayer
{
public void MakeSql()
{
if (this is SqlDataLayer)
{
// Do something SQL Server related
}
else
{
// Do something OLE DB Related
}
}
}

public SqlDataLayer : DataLayer
{
}

public OleDbDataLayer : DataLayer
{
}

DavidM.Kean at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Not exactly, I'm looking for a way to automatically assign an identifier (or enumerate in the worst case --maybe I can assign that number directly in the class?) my objects, for example:


abstract class Base
{
public void TellMyName()
{
Console.WriteLine(String.Format("My name is {0}", this.GetType().Name));
}
}
class Class1 : Base
{
private string customThing;
}
class Class2 : Base
{
public long whatever;
}
class Program
{
static void Main(string[] args)
{
Class1 prod1 = new Class1();
prod1.TellMyName();
Class2 prod2 = new Class2();
prod2.TellMyName();
Console.ReadLine();
}
}


Now, instead of "TellMyName()", suppouse I wanted a way to identify each Class with a number, a number that needs to be saved in the column of a table, how can I do this?
I need to map/relate two kind of objects (tables actually), so the method in the Base (abstract) class would work with both Class1 and Class2.
Thanks!
Edgar at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3

What about something like this:



abstract class Base
{
protected virtual int Identifier
{
get;
}
}

class Class1 : Base
{
protected override int Identifier
{
get { return 1; }
}
}

class Class2 : Base
{
protected override int Identifier
{
get { return 2; }
}
}

DavidM.Kean at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4
Yes, a few minutes after my previous post I noticed I needed some sleep :)
Thanks for the reply!
Edgar at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 5

I believe that any DataLayer must be a simple code block, that they allow operations against DB.

That code block would not have to know on the Business Entities. Single to specialize it is to execute the operations (Store Procedures and SQL Sentences) against the engine DB (SQL, Oracle, DB2, etc.), with which this setting.

Finally, I invite to you to download the DataLayer.Primitives Public Version.

This is very cool Data Layer :)

DataLayer.Primitives - Readme!
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=1389

Cheers,

Javier Luna
http://guydotnetxmlwebservices.blogspot.com/

JavierLuna at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 6
Sounds insteresting, I'll check it out.
EdgardoRossetto at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified