public static NamespaceInfo[] CreateEventTemplateInformation(AssemblyDefinition[] targetAssemblies) { var publicTypesWithEvents = targetAssemblies .SelectMany(x => SafeGetTypes(x)) .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", }; 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), }).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; }
public static MethodDefinition[] GetPublicDelegateMethods(TypeDefinition t) { var bannedMethods = new[] { "Dispose", "Finalize" }; return t.Methods .Where(x => x.IsVirtual && !x.IsConstructor && !x.IsSetter && x.ReturnType.FullName == "System.Void") .Where(x => x.Parameters.All(y => y.ParameterType.FullName.Contains("&") == false)) .Where(x => !bannedMethods.Contains(x.Name)) .GroupBy(x => x.Name).Select(x => x.OrderByDescending(y => y.Parameters.Count).First()) .ToArray(); }