Код: Выделить всё
public abstract class ChildBase;
public class Parent1Child : ChildBase;
public class Parent2Child : ChildBase;
public class ParentBase
where T1 : ChildBase
{
public List Children = new List();
}
public class Parent1 : ParentBase
;
Ниже приведены попытки:
Код: Выделить всё
public static class ParentExtensions
{
public static void Test1(this ParentBase parent)
where T : ChildBase
{
var children = parent.Children;
}
}
public static class EfExtensions
{
public static void Test2(this EntityTypeBuilder builder)
where TEntity : ParentBase
{
builder.HasMany(x => x.Children).WithOne();
}
public static void Test3(this EntityTypeBuilder builder)
where TEntity : ParentBase
where TChild : ChildBase
{
builder.HasMany(x => x.Children).WithOne();
}
}
Код: Выделить всё
var parent = new Parent1();
parent.Test1(); // works
Код: Выделить всё
EntityTypeBuilder
builder;
builder.Test2(); // wrong
builder.Test3(); // wrong
builder.Test3(); // works!
Подробнее здесь: https://stackoverflow.com/questions/786 ... on-methods
Мобильная версия