mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Improved type constraint checks constrained by other generic params
This commit is contained in:
parent
10682e67af
commit
06ceaf617b
3 changed files with 55 additions and 26 deletions
|
@ -165,6 +165,19 @@ namespace Tests
|
|||
public static int GenClassMethodB(GenClass<int> a) { return a.test++; }
|
||||
public static int GenClassMethodC<A>(A a) where A : GenClass<int> { return a.test += 1; }
|
||||
|
||||
public static TDerived AssertSubtype<TBase, TDerived>(TBase instance)
|
||||
where TDerived : TBase
|
||||
where TBase : class
|
||||
{
|
||||
if (instance == null)
|
||||
Runtime.FatalError();
|
||||
if (TDerived derived = instance as TDerived)
|
||||
{
|
||||
return derived;
|
||||
}
|
||||
Runtime.FatalError();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue