@@ -20,6 +20,7 @@ local define = System.defStc
2020local equals = System .equals
2121local zeroFn = System .zeroFn
2222local identityFn = System .identityFn
23+ local debugsetmetatable = System .debugsetmetatable
2324
2425local IComparable = System .IComparable
2526local IComparable_1 = System .IComparable_1
@@ -31,14 +32,61 @@ local ArgumentException = System.ArgumentException
3132local ArgumentNullException = System .ArgumentNullException
3233local FormatException = System .FormatException
3334local OverflowException = System .OverflowException
34- local NullReferenceException = System .NullReferenceException
3535
3636local type = type
3737local tonumber = tonumber
3838local floor = math.floor
3939local setmetatable = setmetatable
4040local tostring = tostring
4141
42+ local function hexForamt (x , n )
43+ return n == " " and " %" .. x or " %0" .. n .. x
44+ end
45+
46+ local function floatForamt (x , n )
47+ return n == " " and " %.f" or " %." .. n .. ' f'
48+ end
49+
50+ local function integerFormat (x , n )
51+ return n == " " and " %d" or " %0" .. n .. ' d'
52+ end
53+
54+ local function exponentialFormat (x , n )
55+ return n == " " and " %" .. x or " %." .. n .. x
56+ end
57+
58+ local formats = {
59+ [' x' ] = hexForamt ,
60+ [' X' ] = hexForamt ,
61+ [' f' ] = floatForamt ,
62+ [' F' ] = floatForamt ,
63+ [' d' ] = integerFormat ,
64+ [' D' ] = integerFormat ,
65+ [' e' ] = exponentialFormat ,
66+ [' E' ] = exponentialFormat
67+ }
68+
69+ local function toStringWithFormat (this , format )
70+ if # format ~= 0 then
71+ local i , j , x , n = format :find (" ^%s*([xXdDfFeE])(%d?)%s*$" )
72+ if i then
73+ local f = formats [x ]
74+ if f then
75+ format = f (x , n )
76+ end
77+ return format :format (this )
78+ end
79+ end
80+ return tostring (this )
81+ end
82+
83+ local function toString (this , format )
84+ if format then
85+ return toStringWithFormat (this , format )
86+ end
87+ return tostring (this )
88+ end
89+
4290local function compareInt (this , v )
4391 if this < v then return - 1 end
4492 if this > v then return 1 end
@@ -54,6 +102,7 @@ local Int = define("System.Int", {
54102 default = zeroFn ,
55103 CompareTo = compareInt ,
56104 Equals = equals ,
105+ ToString = toString ,
57106 GetHashCode = identityFn ,
58107 CompareToObj = function (this , v )
59108 if v == nil then return 1 end
@@ -213,54 +262,6 @@ local function equalsDouble(this, v)
213262 return isNaN (this ) and isNaN (v )
214263end
215264
216- local function hexForamt (x , n )
217- return n == " " and " %" .. x or " %0" .. n .. x
218- end
219-
220- local function floatForamt (x , n )
221- return n == " " and " %.f" or " %." .. n .. ' f'
222- end
223-
224- local function integerFormat (x , n )
225- return n == " " and " %d" or " %0" .. n .. ' d'
226- end
227-
228- local function exponentialFormat (x , n )
229- return n == " " and " %" .. x or " %." .. n .. x
230- end
231-
232- local formats = {
233- [' x' ] = hexForamt ,
234- [' X' ] = hexForamt ,
235- [' f' ] = floatForamt ,
236- [' F' ] = floatForamt ,
237- [' d' ] = integerFormat ,
238- [' D' ] = integerFormat ,
239- [' e' ] = exponentialFormat ,
240- [' E' ] = exponentialFormat
241- }
242-
243- local function toStringWithFormat (this , format )
244- if # format ~= 0 then
245- local i , j , x , n = format :find (" ^%s*([xXdDfFeE])(%d?)%s*$" )
246- if i then
247- local f = formats [x ]
248- if f then
249- format = f (x , n )
250- end
251- return format :format (this )
252- end
253- end
254- return tostring (this )
255- end
256-
257- local function toString (this , format )
258- if format then
259- return toStringWithFormat (this , format )
260- end
261- return tostring (this )
262- end
263-
264265local function equalsObj (this , v )
265266 if type (v ) ~= " number" then
266267 return false
@@ -305,7 +306,9 @@ local Number = define("System.Number", {
305306 end
306307})
307308Number .__call = zeroFn
308- System .debugsetmetatable (0 , Number )
309+ if debugsetmetatable then
310+ debugsetmetatable (0 , Number )
311+ end
309312
310313local function parseDouble (s )
311314 if s == nil then
@@ -360,42 +363,35 @@ local Double = define("System.Double", {
360363})
361364setmetatable (Double , Number )
362365
363- function System .concat (obj )
364- if obj == nil then
365- return " "
366- end
367- local t = type (obj )
368- if t == " table" then
369- return t :ToString ()
370- elseif t == " boolean" then
371- return t and " True" or " False"
372- elseif t == " function" then
373- return " System.Delegate"
366+ if not debugsetmetatable then
367+ local NullReferenceException = System .NullReferenceException
368+ local toString = System .toString
369+
370+ function System .ObjectEquals (this , obj )
371+ if this == nil then throw (NullReferenceException ()) end
372+ local t = type (this )
373+ if t == " number" then
374+ return equalsObj (this , obj )
375+ elseif t == " table" then
376+ return this :EqualsObj (obj )
377+ end
378+ return this == obj
374379 end
375- return tostring (obj )
376- end
377380
378- function System .ObjectEquals (this , obj )
379- if this == nil then throw (NullReferenceException ()) end
380- local t = type (this )
381- if t == " number" then
382- return equalsObj (this , obj )
383- elseif t == " table" then
384- return this :EqualsObj (obj )
381+ function System .ObjectGetHashCode (this )
382+ if this == nil then throw (NullReferenceException ()) end
383+ local t = type (this )
384+ if t == " number" then
385+ return getHashCode (this )
386+ elseif t == " table" then
387+ return this :GetHashCode ()
388+ end
389+ return this
385390 end
386- return this == obj
387- end
388391
389- function System .ObjectGetHashCode (this )
390- if this == nil then throw (NullReferenceException ()) end
391- local t = type (this )
392- if t == " number" then
393- return getHashCode (this )
394- elseif t == " table" then
395- return this :GetHashCode ()
392+ function System .ObjectToString (this )
393+ if this == nil then throw (NullReferenceException ()) end
394+ return toString (this )
396395 end
397- return this
398396end
399397
400-
401-
0 commit comments