1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Fixed generic inner type alias with type extensions

This commit is contained in:
Brian Fiete 2020-06-23 11:54:28 -07:00
parent 8169587b4c
commit 0154b75923
4 changed files with 62 additions and 8 deletions

View file

@ -1,4 +1,6 @@
using System;
using System.Collections;
namespace LibA
{
interface IVal
@ -26,6 +28,11 @@ namespace LibA
let t = new T();
delete t;
}
public static bool DictEquals(Dictionary<String, int> lhs, Dictionary<String, int> rhs)
{
return lhs == rhs;
}
}
}

View file

@ -1,6 +1,7 @@
#pragma warning disable 168
using System;
using System.Collections;
namespace System.Collections
{
@ -16,6 +17,26 @@ namespace System.Collections
return total;
}
}
extension Dictionary<K, V>
{
public static bool operator==(Self lhs, Self rhs) where K : IOpEquals where V : IOpEquals
{
if (lhs.mCount != rhs.mCount)
return false;
for (var kv in ref lhs)
{
if (rhs.TryGetValue(kv.key, var rhsVal))
{
if (*kv.valueRef != rhsVal)
return false;
}
else
return false;
}
return true;
}
}
}
namespace System.Collections
@ -161,6 +182,16 @@ namespace Tests
Test.Assert(val == 110);
}
[Test]
public static void TestDictionary()
{
Dictionary<String, int> dictLhs = scope .() {("Abc", 123), ("Def", 234) };
Dictionary<String, int> dictrhs = scope .() {(scope:: String("Abc"), 123), ("Def", 234) };
Test.Assert(dictLhs == dictrhs);
Test.Assert(!LibA.LibA0.DictEquals(dictLhs, dictrhs));
}
[Test]
public static void TestSharedData()
{