Skip to main content
added 160 characters in body
Source Link
sll
  • 62.7k
  • 22
  • 109
  • 157

As a straightforward solution (not having any details regardign method usage cases) if Address and Address_Accessor both represents some common entity - just introduce a common interface and restrict T to implement this interface, then you would be able insatntiating any of class which implements IAddress and setting to the IAddress reference (behind T).

interface IAddress
{
}

class Address_Accessor : IAddress
class Address : IAddress

internal static void CreateAddress<T>(out T address, bool isSave, int? cID) 
where T: IAddress  
{ 
}

I feel there some design issues around, could you please post a code which calling CreateAddress() method for both Address and Address_accessor cases? Perhaps you are looking for a some kind of abstract factory?

if Address and Address_Accessor both represents some common entity - just introduce a common interface and restrict T to implement this interface, then you would be able insatntiating any of class which implements IAddress and setting to the IAddress reference (behind T).

interface IAddress
{
}

class Address_Accessor : IAddress
class Address : IAddress

internal static void CreateAddress<T>(out T address, bool isSave, int? cID) 
where T: IAddress  
{ 
}

As a straightforward solution (not having any details regardign method usage cases) if Address and Address_Accessor both represents some common entity - just introduce a common interface and restrict T to implement this interface, then you would be able insatntiating any of class which implements IAddress and setting to the IAddress reference (behind T).

interface IAddress
{
}

class Address_Accessor : IAddress
class Address : IAddress

internal static void CreateAddress<T>(out T address, bool isSave, int? cID) 
where T: IAddress  
{ 
}

I feel there some design issues around, could you please post a code which calling CreateAddress() method for both Address and Address_accessor cases? Perhaps you are looking for a some kind of abstract factory?

Source Link
sll
  • 62.7k
  • 22
  • 109
  • 157

if Address and Address_Accessor both represents some common entity - just introduce a common interface and restrict T to implement this interface, then you would be able insatntiating any of class which implements IAddress and setting to the IAddress reference (behind T).

interface IAddress
{
}

class Address_Accessor : IAddress
class Address : IAddress

internal static void CreateAddress<T>(out T address, bool isSave, int? cID) 
where T: IAddress  
{ 
}