Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/EventBuilder/AutoPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public enum AutoPlatform
/// </summary>
Android,

#pragma warning disable SA1300 // Element should begin with upper-case letter
/// <summary>
/// iOS platform.
/// </summary>
iOS,
#pragma warning restore SA1300 // Element should begin with upper-case letter

/// <summary>
/// Mac platform.
Expand Down Expand Up @@ -60,4 +62,4 @@ public enum AutoPlatform
/// </summary>
Essentials
}
}
}
9 changes: 7 additions & 2 deletions src/EventBuilder/Cecil/DelegateTemplateInformation.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Globalization;
using System.Linq;
using EventBuilder.Entities;
using Mono.Cecil;
Expand Down Expand Up @@ -69,7 +70,11 @@ public static NamespaceInfo[] Create(AssemblyDefinition[] targetAssemblies)
string.Join(
", ",
z.Parameters.Select(
a => string.Format("{0} {1}", a.ParameterType.FullName, a.Name))),
a => string.Format(
CultureInfo.InvariantCulture,
"{0} {1}",
a.ParameterType.FullName,
a.Name))),
ParameterTypeList =
string.Join(", ", z.Parameters.Select(a => a.ParameterType.FullName)),
ParameterNameList = string.Join(", ", z.Parameters.Select(a => a.Name))
Expand Down
169 changes: 87 additions & 82 deletions src/EventBuilder/Cecil/EventTemplateInformation.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using EventBuilder.Entities;
using Mono.Cecil;
Expand Down Expand Up @@ -35,6 +37,86 @@ public static class EventTemplateInformation
{ "Tizen.NUI.EventHandlerWithReturnType`3", "Tizen.NUI.EventHandlerWithReturnType" },
};

/// <summary>
/// Creates namespace information from the specified target assemblies.
/// </summary>
/// <param name="targetAssemblies">The target assemblies.</param>
/// <returns>The namespaces in the target assemblies.</returns>
public static NamespaceInfo[] Create(AssemblyDefinition[] targetAssemblies)
{
var publicTypesWithEvents = targetAssemblies
.SelectMany(SafeTypes.GetSafeTypes)
.Where(x => x.IsPublic && !x.HasGenericParameters)
.Select(x => new { Type = x, Events = GetPublicEvents(x) })
.Where(x => x.Events.Length > 0)
.ToArray();

var garbageNamespaceList = new[]
{
"Windows.UI.Xaml.Data",
"Windows.UI.Xaml.Interop",
"Windows.UI.Xaml.Input",
"MonoTouch.AudioToolbox",
"MonoMac.AudioToolbox",
"ReactiveUI.Events",

// Winforms
"System.Collections.Specialized",
"System.Configuration",
"System.ComponentModel.Design",
"System.ComponentModel.Design.Serialization",
"System.CodeDom",
"System.Data.SqlClient",
"System.Data.OleDb",
"System.Data.Odbc",
"System.Data.Common",
"System.Drawing.Design",
"System.Media",
"System.Net",
"System.Net.Mail",
"System.Net.NetworkInformation",
"System.Net.Sockets",
"System.ServiceProcess.Design",
"System.Windows.Input",
"System.Windows.Forms.ComponentModel.Com2Interop",
"System.Windows.Forms.Design",
"System.Timers"
};

var namespaceData = publicTypesWithEvents
.GroupBy(x => x.Type.Namespace)
.Where(x => !garbageNamespaceList.Contains(x.Key))
.Select(x => new NamespaceInfo
{
Name = x.Key,
Types = x.Select(y => new PublicTypeInfo
{
Name = y.Type.Name,
Type = y.Type,
Events = y.Events.Select(z => new PublicEventInfo
{
Name = z.Name,
EventHandlerType = GetRealTypeName(z.EventType),
EventArgsType = GetEventArgsTypeForEvent(z),
ObsoleteEventInfo = GetObsoleteInfo(z)
}).ToArray()
}).ToArray()
}).ToArray();

foreach (var type in namespaceData.SelectMany(x => x.Types))
{
var parentWithEvents = GetParents(type.Type).FirstOrDefault(x => GetPublicEvents(x).Any());
if (parentWithEvents == null)
{
continue;
}

type.Parent = new ParentInfo { Name = parentWithEvents.FullName };
}

return namespaceData;
}

private static string RenameBogusTypes(string typeName)
{
if (SubstitutionList.ContainsKey(typeName))
Expand Down Expand Up @@ -88,6 +170,7 @@ private static string GetRealTypeName(TypeDefinition t)
}

var ret = string.Format(
CultureInfo.InvariantCulture,
"{0}<{1}>",
RenameBogusTypes(t.Namespace + "." + t.Name),
string.Join(",", t.GenericParameters.Select(x => GetRealTypeName(x.Resolve()))));
Expand All @@ -105,6 +188,7 @@ private static string GetRealTypeName(TypeReference t)
}

var ret = string.Format(
CultureInfo.InvariantCulture,
"{0}<{1}>",
RenameBogusTypes(generic.Namespace + "." + generic.Name),
string.Join(",", generic.GenericArguments.Select(GetRealTypeName)));
Expand All @@ -123,7 +207,8 @@ private static string GetRealTypeName(TypeReference t)

private static ObsoleteEventInfo GetObsoleteInfo(EventDefinition ei)
{
var obsoleteAttribute = ei.CustomAttributes.FirstOrDefault(attr => attr.AttributeType.FullName.Equals("System.ObsoleteAttribute"));
var obsoleteAttribute = ei.CustomAttributes
.FirstOrDefault(attr => attr.AttributeType.FullName.Equals("System.ObsoleteAttribute", StringComparison.InvariantCulture));

if (obsoleteAttribute == null)
{
Expand All @@ -144,86 +229,6 @@ private static EventDefinition[] GetPublicEvents(TypeDefinition t)
.ToArray();
}

/// <summary>
/// Creates namespace information from the specified target assemblies.
/// </summary>
/// <param name="targetAssemblies">The target assemblies.</param>
/// <returns>The namespaces in the target assemblies.</returns>
public static NamespaceInfo[] Create(AssemblyDefinition[] targetAssemblies)
{
var publicTypesWithEvents = targetAssemblies
.SelectMany(SafeTypes.GetSafeTypes)
.Where(x => x.IsPublic && !x.HasGenericParameters)
.Select(x => new { Type = x, Events = GetPublicEvents(x) })
.Where(x => x.Events.Length > 0)
.ToArray();

var garbageNamespaceList = new[]
{
"Windows.UI.Xaml.Data",
"Windows.UI.Xaml.Interop",
"Windows.UI.Xaml.Input",
"MonoTouch.AudioToolbox",
"MonoMac.AudioToolbox",
"ReactiveUI.Events",

// Winforms
"System.Collections.Specialized",
"System.Configuration",
"System.ComponentModel.Design",
"System.ComponentModel.Design.Serialization",
"System.CodeDom",
"System.Data.SqlClient",
"System.Data.OleDb",
"System.Data.Odbc",
"System.Data.Common",
"System.Drawing.Design",
"System.Media",
"System.Net",
"System.Net.Mail",
"System.Net.NetworkInformation",
"System.Net.Sockets",
"System.ServiceProcess.Design",
"System.Windows.Input",
"System.Windows.Forms.ComponentModel.Com2Interop",
"System.Windows.Forms.Design",
"System.Timers"
};

var namespaceData = publicTypesWithEvents
.GroupBy(x => x.Type.Namespace)
.Where(x => !garbageNamespaceList.Contains(x.Key))
.Select(x => new NamespaceInfo
{
Name = x.Key,
Types = x.Select(y => new PublicTypeInfo
{
Name = y.Type.Name,
Type = y.Type,
Events = y.Events.Select(z => new PublicEventInfo
{
Name = z.Name,
EventHandlerType = GetRealTypeName(z.EventType),
EventArgsType = GetEventArgsTypeForEvent(z),
ObsoleteEventInfo = GetObsoleteInfo(z)
}).ToArray()
}).ToArray()
}).ToArray();

foreach (var type in namespaceData.SelectMany(x => x.Types))
{
var parentWithEvents = GetParents(type.Type).FirstOrDefault(x => GetPublicEvents(x).Any());
if (parentWithEvents == null)
{
continue;
}

type.Parent = new ParentInfo { Name = parentWithEvents.FullName };
}

return namespaceData;
}

private static IEnumerable<TypeDefinition> GetParents(TypeDefinition type)
{
var current = type.BaseType != null
Expand Down
5 changes: 4 additions & 1 deletion src/EventBuilder/Cecil/StaticEventTemplateInformation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using EventBuilder.Entities;
using Mono.Cecil;
Expand Down Expand Up @@ -116,6 +117,7 @@ private static string GetRealTypeName(TypeDefinition t)
}

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

var ret = string.Format(
CultureInfo.InvariantCulture,
"{0}<{1}>",
generic.Namespace + "." + generic.Name,
string.Join(",", generic.GenericArguments.Select(GetRealTypeName)));
Expand Down
2 changes: 2 additions & 0 deletions src/EventBuilder/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public class CommandLineOptions
/// Manual generation using the specified assemblies. Use with --platform=NONE.
/// </summary>
[ValueList(typeof(List<string>))]
#pragma warning disable CA2227 // Collection properties should be read only
public List<string> Assemblies { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only

/// <summary>
/// Gets the usage.
Expand Down
2 changes: 1 addition & 1 deletion src/EventBuilder/Entities/PublicTypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public class PublicTypeInfo
/// <summary>
/// Gets or sets the multi parameter methods.
/// </summary>
public MultiParameterMethod[] MultiParameterMethods { get; set; }
public IEnumerable<MultiParameterMethod> MultiParameterMethods { get; set; }
}
}
22 changes: 22 additions & 0 deletions src/EventBuilder/ExitCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace EventBuilder
{
/// <summary>
/// The exit/return code (aka %ERRORLEVEL%) on application exit.
/// </summary>
public enum ExitCode
{
/// <summary>
/// Success
/// </summary>
Success = 0,

/// <summary>
/// Error
/// </summary>
Error = 1,
}
}
1 change: 0 additions & 1 deletion src/EventBuilder/Platforms/Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public Android(string referenceAssembliesLocation)
}
else
{

var assemblies =
Directory.GetFiles(
Path.Combine(referenceAssembliesLocation, "MonoAndroid"),
Expand Down
4 changes: 2 additions & 2 deletions src/EventBuilder/Platforms/BasePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ protected BasePlatform()
public abstract AutoPlatform Platform { get; }

/// <inheritdoc />
public List<string> Assemblies { get; set; }
public List<string> Assemblies { get; }

/// <inheritdoc />
public List<string> CecilSearchDirectories { get; set; }
public List<string> CecilSearchDirectories { get; }
}
}
4 changes: 2 additions & 2 deletions src/EventBuilder/Platforms/IPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public interface IPlatform
/// <summary>
/// Gets or sets the assemblies.
/// </summary>
List<string> Assemblies { get; set; }
List<string> Assemblies { get; }

/// <summary>
/// Gets or sets the cecil search directories.
/// Cecil when run on Mono needs some direction as to the location of the platform specific MSCORLIB.
/// </summary>
List<string> CecilSearchDirectories { get; set; }
List<string> CecilSearchDirectories { get; }
}
}
2 changes: 1 addition & 1 deletion src/EventBuilder/Platforms/Mac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace EventBuilder.Platforms
{
// ReSharper disable once InconsistentNaming
/// <summary>
/// Mac platform assemblies and events.
/// </summary>
/// <seealso cref="EventBuilder.Platforms.BasePlatform" />
// ReSharper disable once InconsistentNaming
public class Mac : BasePlatform
{
/// <summary>
Expand Down
6 changes: 5 additions & 1 deletion src/EventBuilder/Platforms/iOS.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand All @@ -13,7 +13,11 @@ namespace EventBuilder.Platforms
/// </summary>
/// <seealso cref="BasePlatform" />
// ReSharper disable once InconsistentNaming
#pragma warning disable IDE1006 // Naming Styles
#pragma warning disable SA1300 // Element should begin with upper-case letter
public class iOS : BasePlatform
#pragma warning restore SA1300 // Element should begin with upper-case letter
#pragma warning restore IDE1006 // Naming Styles
{
/// <summary>
/// Initializes a new instance of the <see cref="iOS"/> class.
Expand Down
2 changes: 1 addition & 1 deletion src/EventBuilder/Platforms/tvOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

namespace EventBuilder.Platforms
{
// ReSharper disable once InconsistentNaming
/// <summary>
/// TV OS platform assemblies and events.
/// </summary>
/// <seealso cref="EventBuilder.Platforms.BasePlatform" />
// ReSharper disable once InconsistentNaming
public class TVOS : BasePlatform
{
/// <summary>
Expand Down
Loading