File tree Expand file tree Collapse file tree 5 files changed +570
-198
lines changed
src/ScriptEngine.HostedScript/Library/TypeDescription Expand file tree Collapse file tree 5 files changed +570
-198
lines changed Original file line number Diff line number Diff line change 1+ /*----------------------------------------------------------
2+ This Source Code Form is subject to the terms of the
3+ Mozilla Public License, v.2.0. If a copy of the MPL
4+ was not distributed with this file, You can obtain one
5+ at http://mozilla.org/MPL/2.0/.
6+ ----------------------------------------------------------*/
7+
8+ using ScriptEngine . HostedScript . Library . Binary ;
9+ using ScriptEngine . Machine ;
10+ using ScriptEngine . Machine . Values ;
11+
12+ namespace ScriptEngine . HostedScript . Library
13+ {
14+ public static class CommonTypes
15+ {
16+ public static readonly TypeDescriptor BinaryData = TypeManager . GetTypeByFrameworkType ( typeof ( BinaryDataContext ) ) ;
17+ public static readonly TypeDescriptor Null = TypeManager . GetTypeByFrameworkType ( typeof ( NullValue ) ) ;
18+ public static readonly TypeDescriptor Boolean = TypeDescriptor . FromDataType ( DataType . Boolean ) ;
19+ public static readonly TypeDescriptor String = TypeDescriptor . FromDataType ( DataType . String ) ;
20+ public static readonly TypeDescriptor Date = TypeDescriptor . FromDataType ( DataType . Date ) ;
21+ public static readonly TypeDescriptor Number = TypeDescriptor . FromDataType ( DataType . Number ) ;
22+ public static readonly TypeDescriptor Type = TypeDescriptor . FromDataType ( DataType . Type ) ;
23+ public static readonly TypeDescriptor Undefined = TypeDescriptor . FromDataType ( DataType . Undefined ) ;
24+
25+ public static readonly TypeDescriptor [ ] Primitives = {
26+ CommonTypes . Boolean ,
27+ CommonTypes . BinaryData ,
28+ CommonTypes . String ,
29+ CommonTypes . Date ,
30+ CommonTypes . Null ,
31+ CommonTypes . Number ,
32+ CommonTypes . Type
33+ } ;
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ /*----------------------------------------------------------
2+ This Source Code Form is subject to the terms of the
3+ Mozilla Public License, v.2.0. If a copy of the MPL
4+ was not distributed with this file, You can obtain one
5+ at http://mozilla.org/MPL/2.0/.
6+ ----------------------------------------------------------*/
7+ using System . Collections . Generic ;
8+ using ScriptEngine . HostedScript . Library . Binary ;
9+ using ScriptEngine . Machine ;
10+ using ScriptEngine . Machine . Values ;
11+
12+ namespace ScriptEngine . HostedScript . Library
13+ {
14+ internal class TypeComparer : IComparer < TypeTypeValue >
15+ {
16+ public int Compare ( TypeTypeValue x , TypeTypeValue y )
17+ {
18+ if ( x == null )
19+ {
20+ return y == null ? 0 : - 1 ;
21+ }
22+
23+ if ( y == null ) return 1 ;
24+
25+ var primitiveX = PrimitiveIndex ( x ) ;
26+ var primitiveY = PrimitiveIndex ( y ) ;
27+
28+ if ( primitiveX != - 1 )
29+ {
30+ if ( primitiveY != - 1 )
31+ return primitiveX - primitiveY ;
32+
33+ return - 1 ;
34+ }
35+
36+ if ( primitiveY != - 1 )
37+ return 1 ;
38+
39+ return x . Value . ID . CompareTo ( y . Value . ID ) ;
40+ }
41+
42+ private static int PrimitiveIndex ( TypeTypeValue type )
43+ {
44+ var typeDescriptor = TypeManager . GetTypeDescriptorFor ( type ) ;
45+ for ( var primitiveIndex = 0 ; primitiveIndex < CommonTypes . Primitives . Length ; primitiveIndex ++ )
46+ {
47+ if ( typeDescriptor . Equals ( CommonTypes . Primitives [ primitiveIndex ] ) )
48+ {
49+ return primitiveIndex ;
50+ }
51+ }
52+
53+ return - 1 ;
54+ }
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments