Hi Marty,
Thanks for posting in the community.
First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to define a base class,
and you hope the derived class will be forced to call some code(generate
GUID), and you do not hope this is done in contructor.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.
Based on my knowledge, a based class can not force the derived class to
call some code in other method than contructor. Since the design of
inheritability of Class is to let the derived to extend the base class and
the derived class can inherit the based class's method, but the derived
class can decide if it will call the base class's method.
e.g.
The
Console.WriteLine("Animal");
will always be called but the
Console.WriteLine("TestMethod in Animal");
will not, the override method will decided if it wants to do that.
namespace TestC_
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public abstract class Animal
{
public Animal()
{
Console.WriteLine("Animal");
}
public virtual void TestMethod()
{
Console.WriteLine("TestMethod in Animal");
}
}
public class Dog : Animal
{
public Dog()
{
Console.WriteLine("Dog");
}
public override void TestMethod()
{
Console.WriteLine("TestMethod in Dog");
//base.TestMethod();
}
[STAThread]
static void Main(string[] args)
{
Dog df = new Dog();
df.TestMethod();
}
}
}
So in your senario, the Dog will need to call the code that generates GUID
explicitly. Also you can write the code in a method and just the call the
method before you do the insert in the derived class.( I assume the Insert
function should be in the derived class)
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.