Created
May 20, 2019 14:36
-
-
Save kekyo/ab565d5637257e62a9ff91f359af43c6 to your computer and use it in GitHub Desktop.
Extract member symbol names, include kanji dot notation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Runtime.CompilerServices; | |
namespace ExtractSymbols | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var tw = Console.Out; | |
var compilerGeneratedAttributeType = typeof(CompilerGeneratedAttribute); | |
var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; | |
foreach (var name in args. | |
SelectMany(assemblyPath => | |
{ | |
var assembly = Assembly.LoadFrom(assemblyPath); | |
var types = assembly.GetTypes(). | |
Where(type => !type.IsDefined(compilerGeneratedAttributeType)). | |
ToArray(); | |
var properties = types.SelectMany(type => type.GetProperties(bindingFlags)). | |
ToArray(); | |
var events = types.SelectMany(type => type.GetEvents(bindingFlags)). | |
ToArray(); | |
var accessorMethods = new HashSet<MethodInfo>( | |
properties.SelectMany(p => new[] { p.GetGetMethod(), p.GetSetMethod() }).Where(m => m != null). | |
Concat(events.SelectMany(e => new[] { e.GetAddMethod(), e.GetRemoveMethod() }).Where(m => m != null))); | |
return types.Select(type => (MemberInfo)type). | |
Concat(types.SelectMany(type => type.GetFields(bindingFlags))). | |
Concat(properties). | |
Concat(events). | |
Concat(types.SelectMany(type => type.GetMethods(bindingFlags)).Where(m => !accessorMethods.Contains(m))); | |
}). | |
Where(member => !member.IsDefined(compilerGeneratedAttributeType) && member.Name.Contains("・")). | |
Select(member => member.Name). | |
Distinct(). | |
OrderBy(name => name)) | |
{ | |
tw.WriteLine("{0},{1}", name, name.Replace("・", string.Empty)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment