using System; using System.Collections.Generic; using Mono.Fuse; using System.Reflection; using Mono.Unix.Native; using System.Runtime.InteropServices; class TypeNavigator : FileSystem { Dictionary assemblies; Dictionary> assembly_results = new Dictionary>(); public TypeNavigator () { assemblies = new Dictionary (); Assembly a = Assembly.Load ("mscorlib"); assemblies [a.GetName().Name] = a; } protected override Errno OnReadDirectory (string path, OpenedPathInfo fi, out IEnumerable paths) { if (path == "/"){ paths = GetRootEntries (); return 0; } path = path.Substring (1); string [] elements = path.Split (new char [] { '/' }); try { if (elements.Length == 1){ string key = elements [0]; Assembly ass = assemblies [key]; if (ass == null){ paths = null; return Errno.ENOENT; } if (assembly_results.ContainsKey (key)) paths = assembly_results [key]; else { paths = assembly_results [key] = GetTypes (ass); } return 0; } if (elements.Length == 2){ Assembly ass = assemblies [elements [0]]; if (ass != null){ Type t = ass.GetType (elements [1]); if (t != null){ paths = GetTypeMembers (t); return 0; } } } } catch (Exception e) { Console.WriteLine ("Exception: {0}", e.ToString ()); } paths = null; return Errno.ENOENT; } private IEnumerable GetRootEntries () { yield return "."; yield return ".."; foreach (string val in assemblies.Keys){ Console.WriteLine (" {0}", val); yield return val; } } private IEnumerable GetTypes (Assembly ass) { yield return "."; yield return ".."; foreach (Type t in ass.GetTypes()) yield return t.FullName; } private IEnumerable GetTypeMembers (Type t) { yield return "."; yield return ".."; MemberInfo [] mi = t.GetMembers (); foreach (MemberInfo m in mi) yield return m.Name; } protected override Errno OnGetPathStatus (string path, ref Stat stbuf) { int sep = 0; foreach (char c in path){ if (c == '/') sep++; } stbuf = new Stat (); if (sep < 3){ stbuf.st_mode = FilePermissions.S_IFDIR | NativeConvert.FromOctalPermissionString ("0755"); stbuf.st_nlink = 1; } else { stbuf.st_mode = FilePermissions.S_IFREG | NativeConvert.FromOctalPermissionString ("0444"); stbuf.st_nlink = 1; } stbuf.st_size = 0; return 0; } public static void Main (string [] args) { if (args.Length < 1){ Console.WriteLine ("Error: must specify a directory to mount at"); return; } using (TypeNavigator t = new TypeNavigator ()){ t.MountPoint = args [0]; t.Start (); } } }