I have class A and B (just sample)
public class A
{
public long Id { get; set; }
public string Name { get; set; }
}
public class B : A
{
public B(long id,string name)
{
}
}
And want to do
var b = new B(100, "myName");
Save(b);
I have a save method that I want to allow only types inherited from A Class and also have uses the constructor that accept two parameters
// I know this will work if my Class B has public B() {},
//but not sure how to restrict to have only the once which accept constructor with two parameters
private void Save<T>(T target) where T : A, new ()
{
//do something
}