P
Paul
I presume you mean like a factory method but not.
try this...
Changes in the Generics where clause to allow you to create new objects of
T, and a get instance method and some methods so we can identify the
intances.
Hope this helps
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Generics_test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine((A.GetType().Name));
Console.WriteLine(B.GetType().Name);
Console.WriteLine((A.GetInstance().Name()));
Console.WriteLine(B.GetInstance().Name());
Console.ReadLine();
}
public abstract class BaseClass<T> where T : BaseClass<T>,new()
{
public new static Type GetType()
{
return typeof(T);
}
public static BaseClass<T> GetInstance()
{
return new T();
}
public abstract string Name();
}
public class A : BaseClass<A>
{
public override string Name()
{
return "A";
}
}
public class B : BaseClass<B>
{
public override string Name()
{
return"B";
}
}
}
}
try this...
Changes in the Generics where clause to allow you to create new objects of
T, and a get instance method and some methods so we can identify the
intances.
Hope this helps
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Generics_test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine((A.GetType().Name));
Console.WriteLine(B.GetType().Name);
Console.WriteLine((A.GetInstance().Name()));
Console.WriteLine(B.GetInstance().Name());
Console.ReadLine();
}
public abstract class BaseClass<T> where T : BaseClass<T>,new()
{
public new static Type GetType()
{
return typeof(T);
}
public static BaseClass<T> GetInstance()
{
return new T();
}
public abstract string Name();
}
public class A : BaseClass<A>
{
public override string Name()
{
return "A";
}
}
public class B : BaseClass<B>
{
public override string Name()
{
return"B";
}
}
}
}