Exemplo n.º 1
0
        private void UpdateItems()
        {
            List <ListViewItem> list = new List <ListViewItem>();

            if (_comTypeInfo != null)
            {
                foreach (ComFunctionInfo comFunctionInfo in _comTypeInfo.GetMethods(true))
                {
                    ListViewItem item = new ListViewItem(comFunctionInfo.Name);
                    item.SubItems.Add(comFunctionInfo.Description);
                    item.ImageIndex = MethodImageIndex;
                    item.Tag        = comFunctionInfo;

                    if (comFunctionInfo.IsRestricted)
                    {
                        item.ForeColor = Color.DarkGray;
                    }

                    list.Add(item);
                }

                foreach (ComPropertyInfo comPropertyInfo in _comTypeInfo.GetProperties(true))
                {
                    ListViewItem item = new ListViewItem(comPropertyInfo.Name);
                    item.SubItems.Add(comPropertyInfo.Description);
                    item.ImageIndex = PropertyImageIndex;
                    item.Tag        = comPropertyInfo;

                    if (comPropertyInfo.GetFunction != null)
                    {
                        if (comPropertyInfo.GetFunction.IsRestricted)
                        {
                            item.ForeColor = Color.DarkGray;
                        }
                    }

                    list.Add(item);
                }

                foreach (ComVariableInfo comVariableInfo in _comTypeInfo.Variables)
                {
                    ListViewItem item = new ListViewItem(comVariableInfo.Name);
                    item.SubItems.Add(comVariableInfo.Description);
                    item.ImageIndex = ConstantImageIndex;
                    item.Tag        = comVariableInfo;

                    list.Add(item);
                }

                if (_comTypeInfo is ComCoClassInfo)
                {
                    ComCoClassInfo comCoClassInfo = (ComCoClassInfo)_comTypeInfo;
                    foreach (ComFunctionInfo comFunctionInfo in comCoClassInfo.Events)
                    {
                        ListViewItem item = new ListViewItem(comFunctionInfo.Name);
                        item.SubItems.Add(comFunctionInfo.Description);
                        item.ImageIndex = EventImageIndex;
                        item.Tag        = comFunctionInfo;
                        list.Add(item);
                    }
                }
                else
                {
                }
            }

            BeginUpdate();
            Items.Clear();
            Items.AddRange(list.ToArray());
            AutoResizeColumns();
            EndUpdate();
        }
Exemplo n.º 2
0
        private ComTreeNode[] GetChildren(ComPtr comPtr)
        {
            if (comPtr == null)
            {
                return new ComTreeNode[] { }
            }
            ;

            ComTypeInfo comTypeInfo = comPtr.TryGetComTypeInfo();

            if (comTypeInfo == null)
            {
                return new ComTreeNode[] { }
            }
            ;

            List <ComTreeNode> childNodes = new List <ComTreeNode>();

            try
            {
                foreach (ComPropertyInfo comPropertyInfo in comTypeInfo.Properties)
                {
                    // Special case. MailSession is a PITA property that causes modal dialog.
                    if (comPropertyInfo.Name.Equals("MailSession"))
                    {
                        continue;
                    }

                    ComTreeNode comTreeNode = GetChild(comPtr, comPropertyInfo);

                    if (comTreeNode != null)
                    {
                        if ((comTreeNode is ComPropertyTreeNode) && (_showProperties == false))
                        {
                            continue;
                        }

                        childNodes.Add(comTreeNode);
                    }
                }

                if (comPtr.TryIsCollection())
                {
                    List <ComTreeNode> collectionChildNodes = new List <ComTreeNode>();
                    int count      = comPtr.TryGetItemCount();
                    int foundCount = 0;

                    try
                    {
                        ComFunctionInfo comFunctionInfo = comTypeInfo.Methods.Where(x => x.Name.Equals("Item", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                        if (comFunctionInfo != null)
                        {
                            object returnValue = null;

                            // Solid Edge is supposed to be 1 based index.
                            for (int i = 1; i <= count; i++)
                            {
                                returnValue = null;
                                if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { i }, out returnValue)))
                                {
                                    ComPtr pItem = returnValue as ComPtr;
                                    if ((pItem != null) && (pItem.IsInvalid == false))
                                    {
                                        ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                        comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, i);
                                        comPtrItemTreeNode.Nodes.Add("...");
                                        collectionChildNodes.Add(comPtrItemTreeNode);
                                        foundCount++;
                                    }
                                }
                            }

                            try
                            {
                                // Some collections are 0 based.
                                // Application->Customization->RibbonBarThemes seems to be 0 based.
                                if (foundCount == (count - 1))
                                {
                                    returnValue = null;
                                    if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { 0 }, out returnValue)))
                                    {
                                        ComPtr pItem = returnValue as ComPtr;
                                        if ((pItem != null) && (pItem.IsInvalid == false))
                                        {
                                            ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                            comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, 0);
                                            comPtrItemTreeNode.Nodes.Add("...");
                                            collectionChildNodes.Insert(0, comPtrItemTreeNode);
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                        GlobalExceptionHandler.HandleException();
                    }

                    childNodes.AddRange(collectionChildNodes.ToArray());
                }

                if (_showMethods)
                {
                    foreach (ComFunctionInfo comFunctionInfo in comTypeInfo.GetMethods(true))
                    {
                        if (comFunctionInfo.IsRestricted)
                        {
                            continue;
                        }

                        ComMethodTreeNode comMethodTreeNode = new ComMethodTreeNode(comFunctionInfo);
                        childNodes.Add(comMethodTreeNode);
                    }
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            return(childNodes.ToArray());
        }