1
- using MiddleweightReflection ;
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
2
4
using System ;
3
5
using System . Collections . Generic ;
4
6
using System . Collections . Immutable ;
5
7
using System . Linq ;
6
8
using System . Reflection ;
7
9
10
+ using MiddleweightReflection ;
11
+
8
12
namespace Codegen
9
13
{
10
14
public static class Util
@@ -15,7 +19,7 @@ public static string GetPropFullName(MrProperty p)
15
19
{
16
20
return $ "{ p . DeclaringType . GetFullName ( ) } .{ p . GetName ( ) } ";
17
21
}
18
-
22
+
19
23
public static string ToJsName ( MrProperty prop )
20
24
{
21
25
if ( IsDependencyProperty ( prop ) )
@@ -33,7 +37,7 @@ public static bool IsDependencyProperty(MrProperty prop)
33
37
{
34
38
return false ; // special case Windows.UI.Xaml.DependencyPropertyChangedEventArgs.Property
35
39
}
36
- return prop . GetName ( ) . EndsWith ( "Property" ) &&
40
+ return prop . GetName ( ) . EndsWith ( "Property" ) &&
37
41
prop . GetPropertyType ( ) . GetName ( ) == "DependencyProperty" ;
38
42
}
39
43
@@ -165,12 +169,14 @@ public static string GetCppWinRTType(MrType t)
165
169
166
170
167
171
public static HashSet < FakeEnum > fakeEnums = new HashSet < FakeEnum > ( ) ;
168
- private static HashSet < MrType > enumsToGenerateConvertersFor = new ( ) ;
169
- public static IReadOnlyList < MrType > GetEnums ( ) {
172
+ private static HashSet < MrType > enumsToGenerateConvertersFor = new ( ) ;
173
+ public static IReadOnlyList < MrType > GetEnums ( )
174
+ {
170
175
return enumsToGenerateConvertersFor . OrderBy ( e => Util . GetTSNamespace ( e ) ) . ToImmutableList ( ) ;
171
176
}
172
177
173
- public static void VisitEnum ( MrType t ) {
178
+ public static void VisitEnum ( MrType t )
179
+ {
174
180
enumsToGenerateConvertersFor . Add ( t ) ;
175
181
}
176
182
@@ -241,7 +247,8 @@ private static ViewManagerPropertyType GetVMPropertyType(MrType propType)
241
247
return ViewManagerPropertyType . Map ;
242
248
}
243
249
244
- if ( TypeMapping . TryGetValue ( propType . GetFullName ( ) , out var mapping ) ) {
250
+ if ( TypeMapping . TryGetValue ( propType . GetFullName ( ) , out var mapping ) )
251
+ {
245
252
return mapping . VM ;
246
253
}
247
254
@@ -469,7 +476,8 @@ public static string GetJsTypeProperty(MrType t, Dictionary<string, List<MrType>
469
476
if ( listDerived . Count ( ) < 5 )
470
477
{
471
478
return string . Join ( " | " , listDerived ) ;
472
- } else
479
+ }
480
+ else
473
481
{
474
482
return string . Join ( " |\n " , listDerived ) ;
475
483
}
@@ -486,7 +494,7 @@ public static string GetEventArgsTSType(MrType t, string prefix)
486
494
487
495
public static string GetEventArgsTSName ( MrEvent evt , string prefix = "" )
488
496
{
489
- var evtType = evt . GetEventType ( ) ;
497
+ var evtType = evt . GetEventType ( ) ;
490
498
if ( evtType . GetPrettyFullName ( ) . StartsWith ( "Windows.Foundation.TypedEventHandler<" ) )
491
499
{
492
500
var evtArgs = evtType . GetGenericArguments ( ) [ 1 ] ;
@@ -609,7 +617,7 @@ public static IEnumerable<Command> GetCommands(string typeName)
609
617
return new Command [ ] { } ;
610
618
}
611
619
612
- public static HashSet < MrType > eventArgsTypes = new ( new NameEqualityComparer ( ) ) ;
620
+ public static HashSet < MrType > eventArgsTypes = new ( new NameEqualityComparer ( ) ) ;
613
621
public static void FoundEventArgsType ( MrType type )
614
622
{
615
623
if ( type . GetFullName ( ) == "System.Object" )
@@ -619,7 +627,7 @@ public static void FoundEventArgsType(MrType type)
619
627
eventArgsTypes . Add ( type ) ;
620
628
}
621
629
622
- public static Dictionary < string , IEnumerable < string > > eventArgsMethods { get ; private set ; } = new ( ) ;
630
+ public static Dictionary < string , IEnumerable < string > > eventArgsMethods { get ; private set ; } = new ( ) ;
623
631
public static IEnumerable < string > GetEventArgsMethods ( string typeName )
624
632
{
625
633
if ( Util . eventArgsMethods . TryGetValue ( typeName , out var ms ) )
@@ -631,7 +639,8 @@ public static IEnumerable<string> GetEventArgsMethods(string typeName)
631
639
632
640
private static string GetEventArgMethodParamType ( string name , MrType paramType )
633
641
{
634
- if ( Util . DerivesFrom ( paramType , $ "{ XamlNames . XamlNamespace } .DependencyObject") ) {
642
+ if ( Util . DerivesFrom ( paramType , $ "{ XamlNames . XamlNamespace } .DependencyObject") )
643
+ {
635
644
return "tag: number" ;
636
645
}
637
646
return $ "{ name } : { GetTypeScriptType ( paramType ) } ";
@@ -642,7 +651,7 @@ public static string GetEventArgsMethodArgs(MrType argType, string methodName)
642
651
argType . GetMethodsAndConstructors ( out var methods , out var ctors ) ;
643
652
var method = methods . Where ( m => m . GetName ( ) == methodName ) . First ( ) ;
644
653
var inputParams = method . GetParameters ( ) . Where ( p => p . Attributes . HasFlag ( System . Reflection . ParameterAttributes . In ) ) ;
645
- string paramTypes = string . Join ( ", " , inputParams . Select ( p =>
654
+ string paramTypes = string . Join ( ", " , inputParams . Select ( p =>
646
655
GetEventArgMethodParamType ( p . GetParameterName ( ) , p . GetParameterType ( ) ) ) ) ;
647
656
return paramTypes ;
648
657
}
@@ -660,7 +669,8 @@ public static string GetEventArgsMethodReturnType(MrType argType, string methodN
660
669
var allTypes = string . Join ( ", " , outParamTypes . Append ( retType ) ) ;
661
670
return $ "{{ { allTypes } }}";
662
671
663
- } else
672
+ }
673
+ else
664
674
{
665
675
return GetTypeScriptType ( method . ReturnType ) ;
666
676
}
0 commit comments