Skip to content

Commit 414ac12

Browse files
committed
fix some error by BridgeNet Test case
1 parent a15c7bc commit 414ac12

19 files changed

Lines changed: 337 additions & 149 deletions

File tree

‎CSharp.lua/CoreSystem.Lua/CoreSystem/Array.lua‎

Lines changed: 83 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,24 @@ local function addRange(t, collection)
176176
t.version = t.version + 1
177177
end
178178

179+
local function unset()
180+
throw(NotSupportedException("Collection is read-only."))
181+
end
182+
183+
local function fill(t, f, e, v)
184+
while e >= f do
185+
t[e] = v
186+
e = e - 1
187+
end
188+
end
189+
179190
local function buildArray(T, len, t)
180191
if t == nil then
181192
t = {}
182193
if len > 0 then
183194
local default = T.__genericT__:default()
184-
if default == nil then
185-
default = null
186-
end
187-
for i = 1, len do
188-
t[i] = default
189-
end
195+
if default == nil then default = null end
196+
fill(t, 1, len, default)
190197
end
191198
else
192199
if len > 0 then
@@ -203,17 +210,6 @@ local function buildArray(T, len, t)
203210
return setmetatable(t, T)
204211
end
205212

206-
local function unset()
207-
throw(NotSupportedException("Collection is read-only."))
208-
end
209-
210-
local function fill(t, f, e, v)
211-
while e >= f do
212-
t[e] = v
213-
e = e - 1
214-
end
215-
end
216-
217213
local function indexOf(t, v, startIndex, count)
218214
if t == nil then throw(ArgumentNullException("array")) end
219215
local len = #t
@@ -343,8 +339,7 @@ local function sort(t, comparer)
343339
end
344340
end
345341

346-
local ArrayEnumerator = {
347-
__index = false,
342+
local ArrayEnumerator = define("System.ArrayEnumerator", {
348343
getCurrent = System.getCurrent,
349344
Dispose = System.emptyFn,
350345
Reset = function (this)
@@ -369,14 +364,41 @@ local ArrayEnumerator = {
369364
end
370365
this.current = nil
371366
return false
372-
end,
373-
}
374-
ArrayEnumerator.__index = ArrayEnumerator
367+
end
368+
})
375369

376370
arrayEnumerator = function (t)
377371
return setmetatable({ list = t, index = 1, version = t.version }, ArrayEnumerator)
378372
end
379373

374+
local ArrayReverseEnumerator = define("System.ArrayReverseEnumerator", {
375+
getCurrent = System.getCurrent,
376+
Dispose = System.emptyFn,
377+
Reset = function (this)
378+
this.index = #this.list
379+
this.current = nil
380+
end,
381+
MoveNext = function (this)
382+
local t = this.list
383+
if this.version ~= t.version then
384+
throwFailedVersion()
385+
end
386+
local index = this.index
387+
local v = t[index]
388+
if v ~= nil then
389+
if v == null then
390+
this.current = nil
391+
else
392+
this.current = v
393+
end
394+
this.index = index - 1
395+
return true
396+
end
397+
this.current = nil
398+
return false
399+
end
400+
})
401+
380402
local function checkArrayIndex(index1, index2)
381403
if index2 then
382404
throw(ArgumentException("Indices length does not match the array rank."))
@@ -407,6 +429,9 @@ Array = {
407429
t.version = t.version + 1
408430
end,
409431
addRange = addRange,
432+
AsReadOnly = function (t)
433+
return System.ReadOnlyCollection(t.__genericT__)(t)
434+
end,
410435
clear = function (t)
411436
local size = #t
412437
if size > 0 then
@@ -546,6 +571,9 @@ Array = {
546571
tmove(t, index + 1, index + count, 1, list)
547572
return setmetatable(list, System.List(t.__genericT__))
548573
end,
574+
reverseEnumerator = function (t)
575+
return setmetatable({ list = t, index = #t, version = t.version }, ArrayReverseEnumerator)
576+
end,
549577
getCount = lengthFn,
550578
getSyncRoot = System.identityFn,
551579
getLongLength = lengthFn,
@@ -554,18 +582,13 @@ Array = {
554582
getIsReadOnly = falseFn,
555583
getIsFixedSize = trueFn,
556584
getRank = System.oneFn,
557-
binarySearchArray = function (t, ...)
558-
local v, index, count, comparer
559-
local len = select("#", ...)
560-
if len == 1 then
561-
v = ...
562-
index = 0
563-
count = #t
564-
elseif len == 2 then
565-
v, index = ...
566-
count = #t - index
567-
elseif len == 3 then
568-
index, count, v = ...
585+
BinarySearch = function (t, ...)
586+
if t == nil then throw(ArgumentNullException("array")) end
587+
local len = #t
588+
local index, count, v, comparer
589+
local n = select("#", ...)
590+
if n == 1 or n == 2 then
591+
index, count, v, comparer = 0, len, ...
569592
else
570593
index, count, v, comparer = ...
571594
end
@@ -575,7 +598,7 @@ Array = {
575598
comparer = Comparer_1(t.__genericT__).getDefault()
576599
compare = comparer.Compare
577600
else
578-
compare = comparer.compare
601+
compare = comparer.Compare
579602
end
580603
local lo = index
581604
local hi = index + count - 1
@@ -834,22 +857,28 @@ Array = {
834857
end,
835858
GetEnumerator = arrayEnumerator,
836859
GetLength = function (this, dimension)
837-
if dimension ~= 0 then
838-
throw(IndexOutOfRangeException())
839-
end
860+
if dimension ~= 0 then throw(IndexOutOfRangeException()) end
840861
return #this
841862
end,
863+
GetLowerBound = function (this, dimension)
864+
if dimension ~= 0 then throw(IndexOutOfRangeException()) end
865+
return 0
866+
end,
867+
GetUpperBound = function (this, dimension)
868+
if dimension ~= 0 then throw(IndexOutOfRangeException()) end
869+
return #this - 1
870+
end,
842871
GetValue = function (this, index1, index2)
843872
return get(this, checkArrayIndex(index1, index2))
844873
end,
845874
SetValue = function (this, value, index1, index2)
846875
set(this, checkArrayIndex(index1, index2), System.castWithNullable(this.__genericT__, value))
847-
end,
876+
end
848877
}
849878

850879
define("System.Array", function(T)
851880
return {
852-
__inherits__ = { System.IList_1(T), System.IList },
881+
__inherits__ = { System.IList_1(T), System.IReadOnlyList_1(T), System.IList },
853882
__genericT__ = T
854883
}
855884
end, Array)
@@ -915,17 +944,25 @@ local MultiArray = {
915944
end,
916945
GetLength = function (this, dimension)
917946
local rank = this.__rank__
918-
if dimension < 0 or dimension >= #rank then
919-
throw(IndexOutOfRangeException())
920-
end
947+
if dimension < 0 or dimension >= #rank then throw(IndexOutOfRangeException()) end
921948
return rank[dimension + 1]
922949
end,
950+
GetLowerBound = function (this, dimension)
951+
local rank = this.__rank__
952+
if dimension < 0 or dimension >= #rank then throw(IndexOutOfRangeException()) end
953+
return 0
954+
end,
955+
GetUpperBound = function (this, dimension)
956+
local rank = this.__rank__
957+
if dimension < 0 or dimension >= #rank then throw(IndexOutOfRangeException()) end
958+
return #rank - 1
959+
end,
923960
GetValue = function (this, ...)
924961
return get(this, checkMultiArrayIndex(this, ...))
925962
end,
926963
SetValue = function (this, value, ...)
927964
set(this, checkMultiArrayIndex(this, ...), System.castWithNullable(this.__genericT__, value))
928-
end,
965+
end
929966
}
930967

931968
function System.multiArrayFromTable(t, T)
@@ -934,7 +971,7 @@ end
934971

935972
define("System.MultiArray", function(T)
936973
return {
937-
__inherits__ = { System.IList_1(T), System.IList },
974+
__inherits__ = { System.IList_1(T), System.IReadOnlyList_1(T), System.IList },
938975
__genericT__ = T
939976
}
940977
end, MultiArray)
@@ -967,7 +1004,7 @@ local ReadOnlyCollection = {
9671004

9681005
define("System.ReadOnlyCollection", function (T)
9691006
return {
970-
__inherits__ = { System.IList_1(T), System.IReadOnlyCollection_1(T), System.IList },
1007+
__inherits__ = { System.IList_1(T), System.IList, System.IReadOnlyList_1(T) },
9711008
__genericT__ = T
9721009
}
9731010
end, ReadOnlyCollection)

0 commit comments

Comments
 (0)