Fix HashSet constructor. Add HashSet.CopyTo. Add IReadOnlySet. Fix or… · Drake53/CSharp.lua@a312e46 · GitHub
Skip to content

Commit a312e46

Browse files
committed
Fix HashSet constructor. Add HashSet.CopyTo. Add IReadOnlySet. Fix ordering nulls.
1 parent cef7aae commit a312e46

7 files changed

Lines changed: 499 additions & 26 deletions

File tree

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/Dictionary.lua‎

Lines changed: 2 additions & 4 deletions

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/HashSet.lua‎

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,11 @@ end, {
7070
}, 1)
7171

7272
local HashSet = {
73-
__ctor__ = function (this, ...)
74-
local n = select("#", ...)
75-
local collection, comparer
76-
if n == 1 then
77-
local c = ...
78-
if type(c) == "table" then
79-
if c.GetEnumerator then
80-
collection = c
81-
end
82-
comparer = c
83-
end
84-
elseif n == 2 then
85-
collection, comparer = ...
73+
__ctor__ = function (this, collection, comparer)
74+
if type(collection) ~= "table" then
75+
collection = nil
76+
elseif not collection.GetEnumerator then
77+
collection, comparer = nil, collection
8678
end
8779
this.dict = System.Dictionary(this.__genericT__, System.Boolean)(comparer)
8880
if collection then
@@ -236,7 +228,35 @@ local HashSet = {
236228
return match(unWrap(k))
237229
end)
238230
end,
239-
TrimExcess = System.emptyFn
231+
TrimExcess = System.emptyFn,
232+
CopyTo = function (this, array, arrayIndex, count)
233+
arrayIndex = arrayIndex or 0
234+
count = count or this:getCount()
235+
if array == nil then
236+
throw(ArgumentNullException("array"))
237+
end
238+
if arrayIndex < 0 then
239+
throw(System.ArgumentOutOfRangeException("arrayIndex"))
240+
end
241+
if count < 0 then
242+
throw(System.ArgumentOutOfRangeException("count"))
243+
end
244+
local arrayCount = array:getCount()
245+
if arrayIndex >= arrayCount then
246+
throw(System.ArgumentException("arrayIndex"))
247+
end
248+
if arrayIndex + count > arrayCount then
249+
throw(System.ArgumentException("count is greater than the available space from arrayIndex to the end of the destination array"))
250+
end
251+
count = count + arrayIndex
252+
for _, kv in each(this.dict) do
253+
if arrayIndex >= count then
254+
return
255+
end
256+
array:set(arrayIndex, kv[1])
257+
arrayIndex = arrayIndex + 1
258+
end
259+
end
240260
}
241261

242262
function System.hashSetFromTable(t, T)
@@ -245,7 +265,7 @@ end
245265

246266
System.HashSet = System.define("System.Collections.Generic.HashSet", function(T)
247267
return {
248-
base = { System.ICollection_1(T), System.ISet_1(T) },
268+
base = { System.ISet_1(T), System.IReadOnlySet_1(T) },
249269
__genericT__ = T,
250270
__genericTKey__ = T,
251271
}

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/Linq.lua‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ local isArrayLike = System.isArrayLike
2828
local isDictLike = System.isDictLike
2929
local Array = System.Array
3030
local arrayEnumerator = Array.GetEnumerator
31+
local null = System.null
3132

3233
local NullReferenceException = System.NullReferenceException
3334
local ArgumentNullException = System.ArgumentNullException
@@ -436,10 +437,11 @@ local function orderBy(source, keySelector, comparer, TKey, descending)
436437
if comparer == nil then comparer = Comparer_1(TKey).getDefault() end
437438
local keys = {}
438439
local function getKey(t)
439-
local k = keys[t]
440+
local key = t or t == nil and null
441+
local k = keys[key]
440442
if k == nil then
441443
k = keySelector(t)
442-
keys[t] = k
444+
keys[key] = k
443445
end
444446
return k
445447
end
@@ -485,10 +487,11 @@ local function thenBy(source, keySelector, comparer, TKey, descending)
485487
if comparer == nil then comparer = Comparer_1(TKey).getDefault() end
486488
local keys = {}
487489
local function getKey(t)
488-
local k = keys[t]
490+
local key = t or t == nil and null
491+
local k = keys[key]
489492
if k == nil then
490493
k = keySelector(t)
491-
keys[t] = k
494+
keys[key] = k
492495
end
493496
return k
494497
end

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Collections/SortedSet.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ local SortedSet = {
4848

4949
local SortedSetFn = System.define("System.Collections.Generic.SortedSet", function(T)
5050
return {
51-
base = { System.ICollection_1(T), System.IReadOnlyCollection_1(T), System.ISet_1(T) },
51+
base = { System.ISet_1(T), System.IReadOnlySet_1(T) },
5252
__genericT__ = T,
5353
}
5454
end, SortedSet, 1)

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Interfaces.lua‎

Lines changed: 6 additions & 0 deletions

0 commit comments

Comments
 (0)