mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-16 23:34:10 +02:00
Added extension methods
This commit is contained in:
parent
c1a2bd79e1
commit
e1c340a711
12 changed files with 507 additions and 225 deletions
59
IDEHelper/Tests/src/ExtensionMethods.bf
Normal file
59
IDEHelper/Tests/src/ExtensionMethods.bf
Normal file
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using static Tests.ExtensionMethods.ClassB;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
class ExtensionMethods
|
||||
{
|
||||
public static int Remove(this String str, float val, float val2)
|
||||
{
|
||||
return 123;
|
||||
}
|
||||
|
||||
class ClassA
|
||||
{
|
||||
public static void Test()
|
||||
{
|
||||
Test.Assert("Abc".Remove(1.2f, 2.3f) == 123);
|
||||
}
|
||||
}
|
||||
|
||||
public class ClassB
|
||||
{
|
||||
public static int Flop(this String str, int a)
|
||||
{
|
||||
return a + 1000;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
ClassA.Test();
|
||||
|
||||
Test.Assert("Test".Flop(234) == 1234);
|
||||
|
||||
List<int> iList = scope .();
|
||||
iList.Add(3);
|
||||
iList.Add(20);
|
||||
iList.Add(100);
|
||||
|
||||
Test.Assert(iList.Total() == 123);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
public static T Total<T>(this List<T> list) where T : IOpAddable
|
||||
{
|
||||
T total = default;
|
||||
for (let val in list)
|
||||
total += val;
|
||||
return total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue