Skip to content

Commit df450cd

Browse files
olevettglennawatson
authored andcommitted
housekeeping: tidying of build warnings in event builder (#1826)
1 parent e6cad56 commit df450cd

File tree

14 files changed

+142
-110
lines changed

14 files changed

+142
-110
lines changed

src/EventBuilder/AutoPlatform.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ public enum AutoPlatform
1515
/// </summary>
1616
Android,
1717

18+
#pragma warning disable SA1300 // Element should begin with upper-case letter
1819
/// <summary>
1920
/// iOS platform.
2021
/// </summary>
2122
iOS,
23+
#pragma warning restore SA1300 // Element should begin with upper-case letter
2224

2325
/// <summary>
2426
/// Mac platform.
@@ -60,4 +62,4 @@ public enum AutoPlatform
6062
/// </summary>
6163
Essentials
6264
}
63-
}
65+
}

src/EventBuilder/Cecil/DelegateTemplateInformation.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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

55
using System;
6+
using System.Globalization;
67
using System.Linq;
78
using EventBuilder.Entities;
89
using Mono.Cecil;
@@ -69,7 +70,11 @@ public static NamespaceInfo[] Create(AssemblyDefinition[] targetAssemblies)
6970
string.Join(
7071
", ",
7172
z.Parameters.Select(
72-
a => string.Format("{0} {1}", a.ParameterType.FullName, a.Name))),
73+
a => string.Format(
74+
CultureInfo.InvariantCulture,
75+
"{0} {1}",
76+
a.ParameterType.FullName,
77+
a.Name))),
7378
ParameterTypeList =
7479
string.Join(", ", z.Parameters.Select(a => a.ParameterType.FullName)),
7580
ParameterNameList = string.Join(", ", z.Parameters.Select(a => a.Name))

src/EventBuilder/Cecil/EventTemplateInformation.cs

Lines changed: 87 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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;
56
using System.Collections.Generic;
7+
using System.Globalization;
68
using System.Linq;
79
using EventBuilder.Entities;
810
using 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

src/EventBuilder/Cecil/StaticEventTemplateInformation.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
using System.Globalization;
23
using System.Linq;
34
using EventBuilder.Entities;
45
using Mono.Cecil;
@@ -116,6 +117,7 @@ private static string GetRealTypeName(TypeDefinition t)
116117
}
117118

118119
var ret = string.Format(
120+
CultureInfo.InvariantCulture,
119121
"{0}<{1}>",
120122
t.Namespace + "." + t.Name,
121123
string.Join(",", t.GenericParameters.Select(x => GetRealTypeName(x.Resolve()))));
@@ -133,6 +135,7 @@ private static string GetRealTypeName(TypeReference t)
133135
}
134136

135137
var ret = string.Format(
138+
CultureInfo.InvariantCulture,
136139
"{0}<{1}>",
137140
generic.Namespace + "." + generic.Name,
138141
string.Join(",", generic.GenericArguments.Select(GetRealTypeName)));

src/EventBuilder/CommandLineOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public class CommandLineOptions
4242
/// Manual generation using the specified assemblies. Use with --platform=NONE.
4343
/// </summary>
4444
[ValueList(typeof(List<string>))]
45+
#pragma warning disable CA2227 // Collection properties should be read only
4546
public List<string> Assemblies { get; set; }
47+
#pragma warning restore CA2227 // Collection properties should be read only
4648

4749
/// <summary>
4850
/// Gets the usage.

src/EventBuilder/Entities/PublicTypeInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public class PublicTypeInfo
5050
/// <summary>
5151
/// Gets or sets the multi parameter methods.
5252
/// </summary>
53-
public MultiParameterMethod[] MultiParameterMethods { get; set; }
53+
public IEnumerable<MultiParameterMethod> MultiParameterMethods { get; set; }
5454
}
5555
}

src/EventBuilder/ExitCode.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace EventBuilder
6+
{
7+
/// <summary>
8+
/// The exit/return code (aka %ERRORLEVEL%) on application exit.
9+
/// </summary>
10+
public enum ExitCode
11+
{
12+
/// <summary>
13+
/// Success
14+
/// </summary>
15+
Success = 0,
16+
17+
/// <summary>
18+
/// Error
19+
/// </summary>
20+
Error = 1,
21+
}
22+
}

src/EventBuilder/Platforms/Android.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public Android(string referenceAssembliesLocation)
3737
}
3838
else
3939
{
40-
4140
var assemblies =
4241
Directory.GetFiles(
4342
Path.Combine(referenceAssembliesLocation, "MonoAndroid"),

src/EventBuilder/Platforms/BasePlatform.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ protected BasePlatform()
2525
public abstract AutoPlatform Platform { get; }
2626

2727
/// <inheritdoc />
28-
public List<string> Assemblies { get; set; }
28+
public List<string> Assemblies { get; }
2929

3030
/// <inheritdoc />
31-
public List<string> CecilSearchDirectories { get; set; }
31+
public List<string> CecilSearchDirectories { get; }
3232
}
3333
}

src/EventBuilder/Platforms/IPlatform.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public interface IPlatform
1919
/// <summary>
2020
/// Gets or sets the assemblies.
2121
/// </summary>
22-
List<string> Assemblies { get; set; }
22+
List<string> Assemblies { get; }
2323

2424
/// <summary>
2525
/// Gets or sets the cecil search directories.
2626
/// Cecil when run on Mono needs some direction as to the location of the platform specific MSCORLIB.
2727
/// </summary>
28-
List<string> CecilSearchDirectories { get; set; }
28+
List<string> CecilSearchDirectories { get; }
2929
}
3030
}

0 commit comments

Comments
 (0)