private static IList <SnoopMethodInformation> GetMethodInfos(object o) { if (o == null) { return(new ObservableCollection <SnoopMethodInformation>()); } var t = o.GetType(); var methods = t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod); var methodsToReturn = new List <SnoopMethodInformation>(); foreach (var method in methods) { if (method.IsSpecialName) { continue; } var info = new SnoopMethodInformation(method); info.MethodName = method.Name; methodsToReturn.Add(info); } methodsToReturn.Sort(); return(methodsToReturn); }
private void SetNullReturnType(SnoopMethodInformation selectedMethod) { if (selectedMethod.MethodInfo.ReturnType == typeof(void)) { this.resultStringContainer.Visibility = this.resultProperties.Visibility = Visibility.Collapsed; } else { this.resultProperties.Visibility = Visibility.Collapsed; this.resultStringContainer.Visibility = Visibility.Visible; this.textBlockResult.Text = string.Empty; this.textBlockResultLabel.Text = "Method evaluated to null"; this.textBlockResult.Visibility = Visibility.Collapsed; } }
private void ComboBoxMethodChanged(object sender, EventArgs e) { var selectedMethod = this.comboBoxMethods.SelectedValue as SnoopMethodInformation; if (selectedMethod == null || this.Target == null) { return; } var parameters = selectedMethod.GetParameters(this.Target.GetType()); this.itemsControlParameters.ItemsSource = parameters; this.parametersContainer.Visibility = parameters.Count == 0 ? Visibility.Collapsed : Visibility.Visible; this.resultProperties.Visibility = this.resultStringContainer.Visibility = Visibility.Collapsed; this.previousMethodInformation = selectedMethod; }
private void TryToInvokeMethod(SnoopMethodInformation selectedMethod, object[] parameters) { try { var returnValue = selectedMethod.MethodInfo.Invoke(this.Target, parameters); if (returnValue == null) { this.SetNullReturnType(selectedMethod); return; } else { this.resultStringContainer.Visibility = this.textBlockResult.Visibility = this.textBlockResultLabel.Visibility = Visibility.Visible; } this.textBlockResultLabel.Text = "Result as string: "; this.textBlockResult.Text = returnValue.ToString(); var properties = returnValue.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); //var properties = PropertyInformation.GetAllProperties(returnValue, new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.All) }); if (properties.Length == 0) { this.resultProperties.Visibility = Visibility.Collapsed; } else { this.resultProperties.Visibility = Visibility.Visible; this.propertyInspector.RootTarget = returnValue; } } catch (Exception exception) { ErrorDialog.ShowDialog(exception, $"Error invoking method '{selectedMethod.MethodName}'", exceptionAlreadyHandled: true); } }