New scriptcs script pack - MemberPrint

I have just published a really simple little ScriptCs (I'm still not sure if I should be capitalising that or not) script pack. It's intended to be used on the REPL. All it does it print some details about the objects and types to help you navigate the REPL more easily. As usual, the code is available on GitHub.

To install, run the following command:

scriptcs -install scriptcs.memberprint

Then just run scriptcs. The easiest way to figure out the API is to run it over itself, like this:

c:\test>scriptcs
scriptcs (ctrl-c or blank to exit)
> var print = Require();
> print.Methods(print);
+   Constructors(Type t, BindingFlags flags, String regex, Boolean verbose) : Void
+   Constructors(Object o, Boolean verbose) : Void
+   Constructors(Object o, String regex, Boolean verbose) : Void
+   Constructors(Type type, Boolean verbose) : Void
+   Constructors(Type type, String regex, Boolean verbose) : Void
+   Constructors(Object o, BindingFlags flags, Boolean verbose) : Void
+   Constructors(Type t, BindingFlags flags, Boolean verbose) : Void
+   Constructors(Object o, BindingFlags flags, String regex, Boolean verbose) : Void
+   Equals(Object obj) : Boolean
+   Events(Object o, Boolean verbose) : Void
+   Events(Object o, String regex, Boolean verbose) : Void
+   Events(Type t, Boolean verbose) : Void
+   Events(Type t, String regex, Boolean verbose) : Void
..... (etc)

MemberPrint supports a few filtering options. You can filter using BindingFlags, just as though you were doing the reflection yourself:

> print.Methods(new System.Text.RegularExpressions.Regex(""), BindingFlags.Static|BindingFlags.Public);
+ # CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname) : Void
+ # CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[] attributes) : Void
+ # CompileToAssembly(RegexCompilationInfo[] regexinfos, AssemblyName assemblyname, CustomAttributeBuilder[] attributes, String resourceFile) : Void
+ # Escape(String str) : String
+ # get_CacheSize() : Int32
+ # IsMatch(String input, String pattern) : Boolean
..... (etc)

You can also filter using regular expression text.

> print.Methods(new System.Text.RegularExpressions.Regex(""), "^Is.+");
+ # IsMatch(String input, String pattern) : Boolean
+ # IsMatch(String input, String pattern, RegexOptions options) : Boolean
+ # IsMatch(String input, String pattern, RegexOptions options, TimeSpan matchTimeout) : Boolean
+   IsMatch(String input) : Boolean
+   IsMatch(String input, Int32 startat) : Boolean

You can run it over types as well as instances. Can't remember the constructors for System.DateTime?

> print.Constructors(typeof(DateTime))
+   .ctor(Int64 ticks)
+   .ctor(Int64 ticks, DateTimeKind kind)
+   .ctor(Int32 year, Int32 month, Int32 day)
+   .ctor(Int32 year, Int32 month, Int32 day, Calendar calendar)
+   .ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second)
+   .ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, DateTimeKind kind)
+   .ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Calendar calendar)
+   .ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond)
+   .ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond, DateTimeKind kind)
+   .ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond, Calendar calendar)
+   .ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second, Int32 millisecond, Calendar calendar, DateTimeKind kind)

There are multiple overloads for each of the following methods:

  • Methods(object o)
  • Properties(object o)
  • Events(object o)
  • Constructors(object o)
  • Members(object o) (this one just calls all of the others)

The code is a little rough around the edges at the moment, but so far I have found it useful enough that I decided to share the script pack.