Skip to content

Instantly share code, notes, and snippets.

@Craftplacer
Last active July 9, 2020 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Craftplacer/ddf4cdc32929ea2a003c852d9e41bcb0 to your computer and use it in GitHub Desktop.
Save Craftplacer/ddf4cdc32929ea2a003c852d9e41bcb0 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Linq;
using System.Reflection;
namespace BruderMussReflektieren
{
class Program
{
static void Main(string[] args)
{
if (args.Length <= 1)
{
Console.WriteLine("Brauche schon .NET Assembly und Klassennamen du huan");
return;
}
var filePath = args[0];
filePath = Path.GetFullPath(filePath);
if (!File.Exists(filePath))
{
Console.WriteLine(".NET assembly ned gefunden.");
return;
}
Console.WriteLine($"Lade laufband: {filePath}");
try
{
var assembly = Assembly.LoadFile(filePath);
var className = args[1];
if (className == null)
{
Console.WriteLine("Hurensohn.");
return;
}
className = className.ToLowerInvariant();
var types = assembly.GetTypes();
var found = types.Where(t => t.IsClass && t.BaseType?.ToString().ToLowerInvariant().Contains(className) == true)
.OrderBy(t => t.ToString())
.ToArray();
Console.WriteLine($"Habe {found.Length} von {types.Length} gefunden:");
foreach (var type in found)
{
Console.ResetColor();
Console.Write($"- {type}");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine($" ({type.BaseType})");
}
}
catch (ReflectionTypeLoadException exFreundin)
{
Console.WriteLine(exFreundin);
Console.WriteLine("Konnte Assemblür ned laden:");
foreach (var exception in exFreundin.LoaderExceptions)
Console.WriteLine(exception.ToString());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment