1- // Licensed to the .NET Foundation under one or more agreements.
1+ // Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5+ using System ;
56using System . Collections . Generic ;
7+ using System . Globalization ;
68using System . Linq ;
79using EventBuilder . Entities ;
810using Mono . Cecil ;
@@ -35,6 +37,86 @@ public static class EventTemplateInformation
3537 { "Tizen.NUI.EventHandlerWithReturnType`3" , "Tizen.NUI.EventHandlerWithReturnType" } ,
3638 } ;
3739
40+ /// <summary>
41+ /// Creates namespace information from the specified target assemblies.
42+ /// </summary>
43+ /// <param name="targetAssemblies">The target assemblies.</param>
44+ /// <returns>The namespaces in the target assemblies.</returns>
45+ public static NamespaceInfo [ ] Create ( AssemblyDefinition [ ] targetAssemblies )
46+ {
47+ var publicTypesWithEvents = targetAssemblies
48+ . SelectMany ( SafeTypes . GetSafeTypes )
49+ . Where ( x => x . IsPublic && ! x . HasGenericParameters )
50+ . Select ( x => new { Type = x , Events = GetPublicEvents ( x ) } )
51+ . Where ( x => x . Events . Length > 0 )
52+ . ToArray ( ) ;
53+
54+ var garbageNamespaceList = new [ ]
55+ {
56+ "Windows.UI.Xaml.Data" ,
57+ "Windows.UI.Xaml.Interop" ,
58+ "Windows.UI.Xaml.Input" ,
59+ "MonoTouch.AudioToolbox" ,
60+ "MonoMac.AudioToolbox" ,
61+ "ReactiveUI.Events" ,
62+
63+ // Winforms
64+ "System.Collections.Specialized" ,
65+ "System.Configuration" ,
66+ "System.ComponentModel.Design" ,
67+ "System.ComponentModel.Design.Serialization" ,
68+ "System.CodeDom" ,
69+ "System.Data.SqlClient" ,
70+ "System.Data.OleDb" ,
71+ "System.Data.Odbc" ,
72+ "System.Data.Common" ,
73+ "System.Drawing.Design" ,
74+ "System.Media" ,
75+ "System.Net" ,
76+ "System.Net.Mail" ,
77+ "System.Net.NetworkInformation" ,
78+ "System.Net.Sockets" ,
79+ "System.ServiceProcess.Design" ,
80+ "System.Windows.Input" ,
81+ "System.Windows.Forms.ComponentModel.Com2Interop" ,
82+ "System.Windows.Forms.Design" ,
83+ "System.Timers"
84+ } ;
85+
86+ var namespaceData = publicTypesWithEvents
87+ . GroupBy ( x => x . Type . Namespace )
88+ . Where ( x => ! garbageNamespaceList . Contains ( x . Key ) )
89+ . Select ( x => new NamespaceInfo
90+ {
91+ Name = x . Key ,
92+ Types = x . Select ( y => new PublicTypeInfo
93+ {
94+ Name = y . Type . Name ,
95+ Type = y . Type ,
96+ Events = y . Events . Select ( z => new PublicEventInfo
97+ {
98+ Name = z . Name ,
99+ EventHandlerType = GetRealTypeName ( z . EventType ) ,
100+ EventArgsType = GetEventArgsTypeForEvent ( z ) ,
101+ ObsoleteEventInfo = GetObsoleteInfo ( z )
102+ } ) . ToArray ( )
103+ } ) . ToArray ( )
104+ } ) . ToArray ( ) ;
105+
106+ foreach ( var type in namespaceData . SelectMany ( x => x . Types ) )
107+ {
108+ var parentWithEvents = GetParents ( type . Type ) . FirstOrDefault ( x => GetPublicEvents ( x ) . Any ( ) ) ;
109+ if ( parentWithEvents == null )
110+ {
111+ continue ;
112+ }
113+
114+ type . Parent = new ParentInfo { Name = parentWithEvents . FullName } ;
115+ }
116+
117+ return namespaceData ;
118+ }
119+
38120 private static string RenameBogusTypes ( string typeName )
39121 {
40122 if ( SubstitutionList . ContainsKey ( typeName ) )
@@ -88,6 +170,7 @@ private static string GetRealTypeName(TypeDefinition t)
88170 }
89171
90172 var ret = string . Format (
173+ CultureInfo . InvariantCulture ,
91174 "{0}<{1}>" ,
92175 RenameBogusTypes ( t . Namespace + "." + t . Name ) ,
93176 string . Join ( "," , t . GenericParameters . Select ( x => GetRealTypeName ( x . Resolve ( ) ) ) ) ) ;
@@ -105,6 +188,7 @@ private static string GetRealTypeName(TypeReference t)
105188 }
106189
107190 var ret = string . Format (
191+ CultureInfo . InvariantCulture ,
108192 "{0}<{1}>" ,
109193 RenameBogusTypes ( generic . Namespace + "." + generic . Name ) ,
110194 string . Join ( "," , generic . GenericArguments . Select ( GetRealTypeName ) ) ) ;
@@ -123,7 +207,8 @@ private static string GetRealTypeName(TypeReference t)
123207
124208 private static ObsoleteEventInfo GetObsoleteInfo ( EventDefinition ei )
125209 {
126- var obsoleteAttribute = ei . CustomAttributes . FirstOrDefault ( attr => attr . AttributeType . FullName . Equals ( "System.ObsoleteAttribute" ) ) ;
210+ var obsoleteAttribute = ei . CustomAttributes
211+ . FirstOrDefault ( attr => attr . AttributeType . FullName . Equals ( "System.ObsoleteAttribute" , StringComparison . InvariantCulture ) ) ;
127212
128213 if ( obsoleteAttribute == null )
129214 {
@@ -144,86 +229,6 @@ private static EventDefinition[] GetPublicEvents(TypeDefinition t)
144229 . ToArray ( ) ;
145230 }
146231
147- /// <summary>
148- /// Creates namespace information from the specified target assemblies.
149- /// </summary>
150- /// <param name="targetAssemblies">The target assemblies.</param>
151- /// <returns>The namespaces in the target assemblies.</returns>
152- public static NamespaceInfo [ ] Create ( AssemblyDefinition [ ] targetAssemblies )
153- {
154- var publicTypesWithEvents = targetAssemblies
155- . SelectMany ( SafeTypes . GetSafeTypes )
156- . Where ( x => x . IsPublic && ! x . HasGenericParameters )
157- . Select ( x => new { Type = x , Events = GetPublicEvents ( x ) } )
158- . Where ( x => x . Events . Length > 0 )
159- . ToArray ( ) ;
160-
161- var garbageNamespaceList = new [ ]
162- {
163- "Windows.UI.Xaml.Data" ,
164- "Windows.UI.Xaml.Interop" ,
165- "Windows.UI.Xaml.Input" ,
166- "MonoTouch.AudioToolbox" ,
167- "MonoMac.AudioToolbox" ,
168- "ReactiveUI.Events" ,
169-
170- // Winforms
171- "System.Collections.Specialized" ,
172- "System.Configuration" ,
173- "System.ComponentModel.Design" ,
174- "System.ComponentModel.Design.Serialization" ,
175- "System.CodeDom" ,
176- "System.Data.SqlClient" ,
177- "System.Data.OleDb" ,
178- "System.Data.Odbc" ,
179- "System.Data.Common" ,
180- "System.Drawing.Design" ,
181- "System.Media" ,
182- "System.Net" ,
183- "System.Net.Mail" ,
184- "System.Net.NetworkInformation" ,
185- "System.Net.Sockets" ,
186- "System.ServiceProcess.Design" ,
187- "System.Windows.Input" ,
188- "System.Windows.Forms.ComponentModel.Com2Interop" ,
189- "System.Windows.Forms.Design" ,
190- "System.Timers"
191- } ;
192-
193- var namespaceData = publicTypesWithEvents
194- . GroupBy ( x => x . Type . Namespace )
195- . Where ( x => ! garbageNamespaceList . Contains ( x . Key ) )
196- . Select ( x => new NamespaceInfo
197- {
198- Name = x . Key ,
199- Types = x . Select ( y => new PublicTypeInfo
200- {
201- Name = y . Type . Name ,
202- Type = y . Type ,
203- Events = y . Events . Select ( z => new PublicEventInfo
204- {
205- Name = z . Name ,
206- EventHandlerType = GetRealTypeName ( z . EventType ) ,
207- EventArgsType = GetEventArgsTypeForEvent ( z ) ,
208- ObsoleteEventInfo = GetObsoleteInfo ( z )
209- } ) . ToArray ( )
210- } ) . ToArray ( )
211- } ) . ToArray ( ) ;
212-
213- foreach ( var type in namespaceData . SelectMany ( x => x . Types ) )
214- {
215- var parentWithEvents = GetParents ( type . Type ) . FirstOrDefault ( x => GetPublicEvents ( x ) . Any ( ) ) ;
216- if ( parentWithEvents == null )
217- {
218- continue ;
219- }
220-
221- type . Parent = new ParentInfo { Name = parentWithEvents . FullName } ;
222- }
223-
224- return namespaceData ;
225- }
226-
227232 private static IEnumerable < TypeDefinition > GetParents ( TypeDefinition type )
228233 {
229234 var current = type . BaseType != null
0 commit comments