public static PropertyDescriptorCollection GetEnumerableChildsAsProperties(ITypeDescriptorContext context, object owner, Attribute[] attributes)
        {
            if (owner == null)
            {
                return(null);
            }
            if (owner is string)
            {
                return(null);
            }
            IEnumerable enumerable = owner as IEnumerable;
            ArrayList   properties = new ArrayList();
            int         index      = 0;

            foreach (object obj2 in enumerable)
            {
                if (obj2 is DictionaryEntry)
                {
                    DictionaryEntry entry      = (DictionaryEntry)obj2;
                    string          customName = HawkeyeUtils.ToStringAsNull(entry.Key);
                    properties.Add(new SimpleChildDescriptor(owner, index, customName, obj2));
                }
                else
                {
                    properties.Add(new SimpleChildDescriptor(owner, index, obj2));
                }
                index++;
                if (index >= ApplicationOptions.Instance.MaxIEnumerableChildsToShow)
                {
                    properties.Add(new SimpleChildDescriptor("[more items where available]", "[max visible:" + ApplicationOptions.Instance.MaxIEnumerableChildsToShow + "]"));
                    break;
                }
            }
            return(DescriptorUtils.GetProperties(properties));
        }
Beispiel #2
0
 private static string EnumToCode(object value)
 {
     if (value is Enum)
     {
         return(HawkeyeUtils.EnumToString((Enum)value));
     }
     return(null);
 }
Beispiel #3
0
        public override void SetValue(object component, object value)
        {
            if (value is IRealValueHolder)
            {
                value = (value as IRealValueHolder).RealValue;
            }

            if (WarningsHelper.Instance.SetPropertyWarning(propInfo.DeclaringType.Name, value))
            {
                //LoggingSystem.Instance.LogSet(propInfo.DeclaringType.Name, propInfo.Name, value);
                CodeChangeLoggingSystem.Instance.LogSet(HawkeyeUtils.GetControlName(component), propInfo.Name, value);
                propInfo.SetValue(component, value, new object[] {});
            }
        }
Beispiel #4
0
        private void Invoke(object[] param)
        {
            try
            {
                if (monitoredObject != null)
                {                       // instance
                    StringBuilder builder = new StringBuilder();
                    foreach (object para in param)
                    {
                        builder.Append(CodeChangeLoggingSystem.Instance.PrepareValueToLog(para));
                        builder.Append(", ");
                    }
                    if (builder.Length > 0)
                    {
                        builder.Remove(builder.Length - 2, 2);
                    }
                    CodeChangeLoggingSystem.Instance.Log(HawkeyeUtils.GetControlName2(monitoredObject) + "." + methodInfo.Name + "( " + builder + " );");
                }

                if (monitoredObject is Form)
                {                       // force an activate to make it easier for controls to relate to their parent form
                    try
                    {
                        (monitoredObject as Form).Activate();
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.ToString());
                    }
                }

                valueOfLastRun = methodInfo.Invoke(monitoredObject, param);
                if (IsVoidMethdod)
                {
                    valueOfLastRun = "<void>";
                }
            }
            catch (TargetInvocationException ex)
            {
                valueOfLastRun = ex.InnerException.ToString();
            }
            catch (Exception ex)
            {
                valueOfLastRun = ex.ToString();
            }
            return;
        }
Beispiel #5
0
        private bool ChangeSelectedObject(object selectedObject)
        {
            if (!CoreApplicationOptions.Instance.AllowSelectOwnedObjects)
            {
                if (selectedObject != null &&
                    selectedObject.GetType().Assembly == typeof(HawkeyeEditor).Assembly)
                {
                    if (!(selectedObject is IAllowSelect))
                    {
                        return(true);
                    }
                }
            }

            try
            {
                propertyGrid.SelectedObject = selectedObject;
                PluginManager.Instance.OnSelectedObjectChanged(selectedObject);

                if (selectedObject != null)
                {
                    string controlName = HawkeyeUtils.GetControlName(selectedObject);
                    if ((controlName == null) || (controlName.Length == 0))
                    {
                        Text = HawkeyeAppUtils.AppName + "(unknown object name)";
                    }
                    else
                    {
                        Text = HawkeyeAppUtils.AppName + controlName;
                    }

                    txtType.Text = selectedObject.GetType().FullName;
                    try
                    {
                        txtToString.Text = selectedObject.ToString();
                    }
                    catch (Exception ex)
                    {
                        txtToString.Text = "<ex:>" + ex.Message;
                        Trace.WriteLine("ChangeSelectedObject: selectedObjectToString:" + ex.ToString(), "Hawkeye");
                    }

                    ShowTail(txtType);
                    ShowTail(txtToString);
                    return(true);
                }

                txtToString.Text = string.Empty;
                if (NativeUtils.IsTargetInDifferentProcess(this.windowFinder.SelectedHandle))
                {
                    if (windowFinder.IsManagedByClassName)
                    {
                        txtType.Text = "<target in different process. release selection to hook>";
                        //TODO: this always return true on x86 machines!
                        bool flag = NativeUtils.IsProcessX64(NativeUtils.GetProcessForWindow(windowFinder.SelectedHandle));
                        Text = HawkeyeAppUtils.AppName + ".Net " + (flag ? "x64 " : "") + "Process";
                    }
                    else
                    {
                        txtType.Text = "<target not in a managed process>";
                        Text         = HawkeyeAppUtils.AppName + "not a managed process";
                    }
                }
                else
                {
                    if (windowFinder.Window.IsValid)
                    {
                        txtToString.Text = "ClassName:" + this.windowFinder.Window.ClassName;
                    }
                    else
                    {
                        txtType.Text = "<no selection or unknown window>";
                    }
                    Text = HawkeyeAppUtils.AppName;
                }
                return(false);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Concat(new object[]
                {
                    "Exception activating object:", selectedObject, ":", ex.ToString()
                }), "Hawkeye");

                txtType.Text     = "Ex:" + ex.Message;
                txtToString.Text = ex.ToString().Replace("\r\n", "--");
                return(true);
            }
        }
Beispiel #6
0
 public override void SetValue(object component, object value)
 {
     CodeChangeLoggingSystem.Instance.Log(string.Concat(new object[] { HawkeyeUtils.GetControlName2(component), this.field.Name, " = ", value, ";" }));
     this.field.SetValue(component, value);
 }