private void OpenFile(string fileName) { // see if we already have this file open. if (!m_OpenViewModels.Contains((vm) => vm.FilePath == fileName)) { DataModels.AssemblyFile newFile = AssemblyFileLoader.LoadFile(fileName); var newVm = new AssemblyFileViewModel(newFile); m_OpenViewModels.Add(newVm); ActiveFileIndex = m_OpenViewModels.Count - 1; } else { ActiveFileIndex = m_OpenViewModels.IndexOf(vm => vm.FileName == fileName); } var activeViewRequest = new ActiveViewRequestMessage(m_ViewId); BroadcastMessage(activeViewRequest); }
public void Run() { try { var filePath = _options.FilePath; var typename = _options.TypeName; Log("ARGS:"); Log($"FilePath: {filePath}"); Log($"TypeName: {typename}"); Type type; if (!string.IsNullOrWhiteSpace(filePath)) { AppDomain domain = null; #if !NETCOREAPP //domain = AppDomain.CreateDomain("LOADER"); #endif var loader = new AssemblyFileLoader(domain); Log("Loading assembly..."); var assembly = loader.Load(filePath); Log(assembly); var definedTypes = assembly.DefinedTypes; Log($"Defined types: {definedTypes?.Count()}"); Log("Getting type..."); type = assembly.GetType(typename, true, true); Log(type); } else { Log("Getting type..."); type = Type.GetType(typename, true, true); Log(type); } Log("Creating instance..."); var instance = Activator.CreateInstance(type); var instanceStr = instance?.ToString(); if (instanceStr == type.FullName) { instanceStr = $"[{type.FullName}]"; } Log(instanceStr); if (_options?.Methods != null) { //var methodsNames = methodnames.Split(','); foreach (var name in _options.Methods) { var method = type.GetMethod(name); if (method == null) { throw new MissingMethodException(type.FullName, name); } Log($"Invoking method '{name}'... "); var res = method.Invoke(instance, null); Log($"Result :: {res}"); } } } catch (Exception ex) { Log($"Exception was thrown!"); Log(ex, LogLevel.Error); } }
public static void Main(string[] args) { var argsSupplied = args != null && args.Length > 0; if (!argsSupplied) { Log($"Usage: {REFLEX_ASSEMBLY}.exe/.dll {{FILEPATH}} {{TYPENAME}}"); } var filePath = args?.Length > 0 ? args[0] : GetInputArg($"Enter {{FILEPATH}}: "); var typename = args?.Length > 1 ? args[1] : GetInputArg($"Enter {{TYPENAME}}: "); var methodnames = args?.Length > 2 ? args[2] : GetInputArg($"Enter {{METHODS}}: "); try { Log("ARGS:"); Log($"FilePath: {filePath}"); Log($"TypeName: {typename}"); Type type; if (!string.IsNullOrWhiteSpace(filePath)) { AppDomain domain = null; #if !NETCOREAPP //domain = AppDomain.CreateDomain("LOADER"); #endif var loader = new AssemblyFileLoader(domain); Log("Loading assembly..."); var assembly = loader.Load(filePath); Log(assembly); var definedTypes = assembly.DefinedTypes; Log($"Defined types: {definedTypes?.Count()}"); Log("Getting type..."); type = assembly.GetType(typename, true, true); Log(type); } else { Log("Getting type..."); type = Type.GetType(typename, true, true); Log(type); } Log("Creating instance..."); var instance = Activator.CreateInstance(type); var instanceStr = instance?.ToString(); if (instanceStr == type.FullName) { instanceStr = $"[{type.FullName}]"; } Log(instanceStr); if (!string.IsNullOrWhiteSpace(methodnames)) { var methodsNames = methodnames.Split(','); foreach (var name in methodsNames) { var method = type.GetMethod(name); if (method == null) { throw new MissingMethodException(type.FullName, name); } Log($"Invoking method '{name}'... "); var res = method.Invoke(instance, null); Log($"Result :: {res}"); } } } catch (Exception ex) { Log($"Exception was thrown!"); Log(ex, LogLevel.Error); } if (Environment.UserInteractive) { Log("Press [ENTER] to exit..."); Console.ReadLine(); } }