Example #1
0
        private void ToggleButton_Click(object sender, RoutedEventArgs e)
        {
            var      b     = sender;
            variable item  = (variable)grid.SelectedItem;
            var      index = variables.IndexOf(item);

            if (item.IsExpanded)
            {
                //variables.Insert(index, new variable() { name = item.name + index, value = "value" + index, Level = item.Level + 1 });
                expandVariable(index);
                return;
            }
            index++;
            if (index >= variables.Count())
            {
                return;
            }
            variable subitem = variables[index];

            while (subitem != null && subitem.Level > item.Level)
            {
                variables.Remove(subitem);
                if (variables.Count > index)
                {
                    subitem = variables[index];
                }
                if (variables.Count == index)
                {
                    subitem = null;
                }
            }
        }
Example #2
0
        private int expandFields(List <string> newVariables, variable item, Type type, object obj, int index)
        {
            if (obj == null && type == null)
            {
                return(index);
            }
            if (type == null)
            {
                type = obj.GetType();
            }
            var fields = type.GetFields();

            //var fields = type.GetFields();
            foreach (var f in fields)
            {
                if (newVariables.Contains(f.Name))
                {
                    continue;
                }
                newVariables.Add(f.Name);
                index++;
                try
                {
                    var subo = f.GetValue(obj);
                    addVariable(f.Name, subo, f.FieldType, index, item.Level + 1);
                }
                catch (Exception ex)
                {
                    addVariable(f.Name, ex, ex.GetType(), index, item.Level + 1);
                }
            }
            return(index);
        }
Example #3
0
        private int expandProperties(List <string> newVariables, variable item, Type type, object obj, int index)
        {
            if (obj == null && type == null)
            {
                return(index);
            }
            if (type == null)
            {
                type = obj.GetType();
            }
            var properties = type.GetProperties();

            foreach (var p in properties)
            {
                if (newVariables.Contains(p.Name))
                {
                    continue;
                }
                newVariables.Add(p.Name);
                try
                {
                    if (p.CanRead)                              // Does the property has a "Get" accessor
                    {
                        if (p.GetIndexParameters().Length == 0) // Ensure that the property does not requires any parameter
                        {
                            var subo = p.GetValue(obj);
                            addVariable(p.Name, subo, p.PropertyType, (index + 1), item.Level + 1);
                            index++;

                            //if (typeof(IEnumerable).IsAssignableFrom(obj.GetType()))
                            //{
                            //    var subo = obj;
                            //    try
                            //    {
                            //        subo = p.GetValue(obj);
                            //    }
                            //    catch (Exception ex)
                            //    {
                            //        var s = ex.ToString();
                            //    }
                            //    addVariable(p.Name, obj, p.PropertyType, (index + 1), item.Level + 1);
                            //    index++;
                            //}
                        }
                    }
                }
                catch (Exception ex)
                {
                    addVariable(p.Name, ex, ex.GetType(), index, item.Level + 1);
                }
            }
            return(index);
        }
Example #4
0
 private int expandInterfaces(List <string> newVariables, variable item, Type type, object obj, int index)
 {
     if (obj == null && type == null)
     {
         return(index);
     }
     if (type == null)
     {
         type = obj.GetType();
     }
     foreach (var _type in type.GetInterfaces())
     {
         index = expandFields(newVariables, item, _type, item.obj, index);
         index = expandProperties(newVariables, item, _type, item.obj, index);
         index = expandInterfaces(newVariables, item, _type, item.obj, index);
     }
     return(index);
 }
Example #5
0
        public void addVariable(string name, object obj, Type type, int index, int level)
        {
            try
            {
                var value   = "(null)";
                var details = "(null)";
                try
                {
                    if (obj != null)
                    {
                        value = obj.ToString();
                    }
                    if (!string.IsNullOrEmpty(value))
                    {
                        details = value;
                        value   = value.Replace(System.Environment.NewLine, "");
                        if (value.Length > 25)
                        {
                            value = value.Substring(0, 22) + "...";
                        }
                    }
                    var exception = obj as Exception;
                    if (exception != null)
                    {
                        value = exception.Message;
                    }
                }
                catch (Exception)
                {
                }
                var v = new variable()
                {
                    name = name, obj = obj, value = value, type = type, details = details, Level = level
                };
                if (type != null)
                {
                    v.typename = type.FullName;
                }
                if (type == typeof(string))
                {
                    v.HasChildren = false;
                }
                if (type == typeof(bool))
                {
                    v.HasChildren = false;
                }
                if (type == typeof(int))
                {
                    v.HasChildren = false;
                }
                if (type == typeof(Int16))
                {
                    v.HasChildren = false;
                }
                if (type == typeof(Int32))
                {
                    v.HasChildren = false;
                }
                if (type == typeof(Guid))
                {
                    v.HasChildren = false;
                }
                if (obj == null)
                {
                    v.HasChildren = false;
                }
                //if (type == typeof()) v.HasChildren = false;

                try
                {
                    variables.Insert(index, v);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }