mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-16 23:34:10 +02:00
Fixed generic extension methods with primitive 'this'
This commit is contained in:
parent
d976ea77e9
commit
222d030aa4
3 changed files with 42 additions and 2 deletions
|
@ -42,11 +42,26 @@ namespace Tests
|
|||
iList.Add(100);
|
||||
|
||||
Test.Assert(iList.Total() == 123);
|
||||
|
||||
float a = 1.2f;
|
||||
float b = 2.3f;
|
||||
Test.Assert(a.CompareIt(b) < 0);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
public static int CompareIt<T>(this T self, T other)
|
||||
where bool: operator T < T
|
||||
{
|
||||
if(self < other)
|
||||
return -1;
|
||||
else if(self > other)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static T Total<T>(this List<T> list) where T : operator T + T
|
||||
{
|
||||
T total = default;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue