Skip to content

Instantly share code, notes, and snippets.

@seansong327
Created June 24, 2016 14:33
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 seansong327/47bad06ace770df84b9854e032195803 to your computer and use it in GitHub Desktop.
Save seansong327/47bad06ace770df84b9854e032195803 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.MsmqIntegration;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
foreach (var item in args)
{
Console.WriteLine(item);
}
//ChildrenClassPrinter printer1 = new ChildrenClassPrinter(PrintBindingType);
//printer1.PrintChildrenClass(typeof(Binding));
PrintBindingType(typeof(WS2007HttpBinding));
//Console.WriteLine();
//ChildrenClassPrinter printer2 = new ChildrenClassPrinter();
//printer2.PrintChildrenClass(typeof(Comparer));
Console.ReadKey();
}
static void PrintBindingType(Type type)
{
if (type.IsAbstract || type.IsNested)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(type.Name);
Console.ForegroundColor = ConsoleColor.Gray;
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(type.Name);
Console.ForegroundColor = ConsoleColor.Gray;
Binding binding = (Binding)Activator.CreateInstance(type, false);
BindingElementCollection elements = binding.CreateBindingElements();
Console.Write(" (");
Console.Write(string.Join(", ", elements.Select(e => e.GetType().Name)));
Console.Write(")");
}
Console.WriteLine();
}
}
public class ChildrenClassPrinter
{
private const string horizontalLine = "─";
private const string verticalLine = "│";
private const string space = " ";
private const string angle = "├";
private Type[] types;
private Action<Type> printType;
public ChildrenClassPrinter() { }
public ChildrenClassPrinter(Action<Type> printType)
{
this.printType = printType;
}
public void PrintChildrenClass(Type type, int level = 0)
{
if(types == null)
{
types = type.Assembly.GetTypes();
}
if (level > 0)
{
for (int i = 1; i < level; i )
{
Console.Write(verticalLine);
Console.Write(space);
}
Console.Write(angle);
Console.Write(horizontalLine);
}
if (printType != null)
{
printType(type);
}
else
{
PrintCommonType(type);
}
foreach (var item in types)
{
if (item.BaseType == type)
{
PrintChildrenClass(item, level 1);
}
}
}
private void PrintCommonType(Type type)
{
if (type.IsAbstract || type.IsNested)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.Write(type.Name);
Console.ForegroundColor = ConsoleColor.Gray;
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(type.Name);
Console.ForegroundColor = ConsoleColor.Gray;
}
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment