コード例 #1
0
        private static IList<SnoopMethodInformation> GetMethodInfos(object o)
        {
            if (o == null)
                return new ObservableCollection<SnoopMethodInformation>();

            Type 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;
        }
コード例 #2
0
        private void TryToInvokeMethod(SnoopMethodInformation selectedMethod, object[] parameters)
        {
            try
            {
                var returnValue = selectedMethod.MethodInfo.Invoke(this.Target, parameters);

                if (returnValue == null)
                {
                    SetNullReturnType(selectedMethod);
                    return;
                }
                else
                {
                    this.resultStringContainer.Visibility = this.textBlockResult.Visibility = this.textBlockResultLabel.Visibility = System.Windows.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 = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    this.resultProperties.Visibility = System.Windows.Visibility.Visible;
                    this.propertyInspector.RootTarget = returnValue;
                }
            }
            catch (Exception ex)
            {
                string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                MessageBox.Show(message, "Error invoking method");
            }
        }
コード例 #3
0
 private void SetNullReturnType(SnoopMethodInformation selectedMethod)
 {
     if (selectedMethod.MethodInfo.ReturnType == typeof(void))
     {
         this.resultStringContainer.Visibility = this.resultProperties.Visibility = System.Windows.Visibility.Collapsed;
     }
     else
     {
         this.resultProperties.Visibility = System.Windows.Visibility.Collapsed;
         this.resultStringContainer.Visibility = System.Windows.Visibility.Visible;
         this.textBlockResult.Text = string.Empty;
         this.textBlockResultLabel.Text = "Method evaluated to null";
         this.textBlockResult.Visibility = System.Windows.Visibility.Collapsed;
     }
 }
コード例 #4
0
        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;

            _previousMethodInformation = selectedMethod;
        }