Example #1
0
        public void addObjectPropertyAndFields_Thread(TreeNode targetNode, object targetObject)
        {
            if (targetObject is String)  // skip strings
                return;

            if (targetObject is IDictionary)
            {
                var dictionary = (IDictionary)targetObject;
                var index = 0;
                foreach (var key in dictionary.Keys)
                {
                    if (key is String)
                        targetNode.add_Node(key.str(), dictionary[key]);
                    else
                    {
                        index++;
                        var value = dictionary[key];
                        targetNode.add_Node("key_{0}: {1}".format(index, key.str()), key);
                        targetNode.add_Node("value_{0}: {1}".format(index, value.str()), value);
                    }
                }
                targetNode.expand();
            }
            else
                if (targetObject is IEnumerable)
                {
                    try
                    {
                        foreach (var item in (targetObject as IEnumerable))
                            targetNode.add_Node(item);
                        targetNode.expand();
                    }
                    catch (Exception ex)
                    {
                        ex.log("in addObjectPropertyAndFields IEnumerable loop");
                    }
                }
                else
                {
                    if (SimpleView)
                    {
                        foreach (var property in targetObject.type().properties())
                        {
                            var propertyValue = PublicDI.reflection.getProperty(property, targetObject);

                            var newNode = targetNode.add_Node(property.Name, propertyValue, false);
                            switch (property.PropertyType.FullName)
                            {
                                case "System.String":
                                case "System.String[]":
                                case "System.Boolean":
                                case "System.DateTime":
                                case "System.Int32":
                                case "System.Int32[]":
                                case "System.Byte":
                                case "System.Int64":
                                    newNode.color(Color.Gray);
                                    break;
                                default:
                                    if (propertyValue.isNull())
                                    {
                                        if (CreateObjectWhenNull)
                                        {
                                            propertyValue = property.PropertyType.ctor();
                                            if (propertyValue.notNull())
                                            {
                                                "CREATE object for type: {0}".debug(propertyValue.type());
                                                PublicDI.reflection.setProperty(property, targetObject, propertyValue);
                                                WinForms_ExtensionMethods_TreeView.set_Tag(newNode, propertyValue);
                                            }
                                            else
                                                "Could not create instance of type: {0}".error(propertyValue.type());
                                        }
                                    }
                                    break;
                            }
                        }
                    }
                    else
                    {
                        //var objectNode = targetNode.add_Node(targetObject.str(), targetObject);
                        targetNode.add_Node("properties", null).add_Nodes(targetObject.type().properties(),
                                                                    (item) => item.Name,
                                                                    (item) => PublicDI.reflection.getProperty(item, targetObject),
                                                                    (item) => false);

                        targetNode.add_Node("fields", null).add_Nodes(targetObject.type().fieldInfos(),
                                                                    (item) => item.Name,
                                                                    (item) => targetObject.field(item.Name), //PublicDI.reflection.getField(item,_object),
                                                                    (item) => false);
                        targetNode.set_Text("{0}             ({1} properties {2} fields)"
                            .format(targetNode.get_Text(),
                                    targetNode.nodes()[1].nodes().size(),
                                    targetNode.nodes()[0].nodes().size()));
                    }
                }
            if (ShowPropertyAndFieldInfo)
            {
                targetNode.add_Node("_PropertyInfo(s)", null).add_Nodes(targetObject.type().properties(),
                                                        (item) => item.Name);
                targetNode.add_Node("_FieldInfo(s)", null).add_Nodes(targetObject.type().fieldInfos(),
                                                        (item) => item.Name);
            }
            if (ShowMethods)
            {
                targetNode.add_Node("MethodInfo(s)", null).add_Nodes(targetObject.type().methods(),
                                                        (item) => item.Name);
            }
        }