Пример #1
0
        private void LoadMembers()
        {
            _members = new List <ComMemberInfo>();

            for (short i = 0; i < _typeAttr.cFuncs; i++)
            {
                IntPtr pFuncDesc = IntPtr.Zero;

                _typeInfo.GetFuncDesc(i, out pFuncDesc);
                ComFunctionInfo comFunctionInfo = new ComFunctionInfo(this, pFuncDesc);

                _members.Add(comFunctionInfo);
            }

            /* Note that these are not always enum constants.  Some properties show up as VARDESC's. */
            for (short i = 0; i < _typeAttr.cVars; i++)
            {
                System.Runtime.InteropServices.ComTypes.VARDESC varDesc;
                IntPtr p = IntPtr.Zero;

                _typeInfo.GetVarDesc(i, out p);
                object constantValue = null;

                try
                {
                    varDesc = p.ToStructure <System.Runtime.InteropServices.ComTypes.VARDESC>();

                    if (varDesc.varkind == VARKIND.VAR_CONST)
                    {
                        constantValue = Marshal.GetObjectForNativeVariant(varDesc.desc.lpvarValue);
                    }
                }
                finally
                {
                    _typeInfo.ReleaseVarDesc(p);
                }

                ComVariableInfo comVariableInfo = new ComVariableInfo(this, varDesc, constantValue);
                _members.Add(comVariableInfo);
            }

            _members.Sort(delegate(ComMemberInfo a, ComMemberInfo b)
            {
                return(a.Name.CompareTo(b.Name));
            });
        }
Пример #2
0
 public ComParameterInfo(ComFunctionInfo comFunctionInfo, string name, System.Runtime.InteropServices.ComTypes.ELEMDESC elemDesc)
 {
     _comFunctionInfo = comFunctionInfo;
     _name            = name;
     _elemDesc        = elemDesc;
 }
Пример #3
0
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            if (_propertyDescriptorCollection == null)
            {
                _propertyDescriptorCollection = new PropertyDescriptorCollection(new PropertyDescriptor[] { }, true);

                ComTypeInfo comTypeInfo = TryGetComTypeInfo();

                if (comTypeInfo != null)
                {
                    List <ComPtrPropertyDescriptor> list = new List <ComPtrPropertyDescriptor>();

                    foreach (ComPropertyInfo comPropertyInfo in comTypeInfo.GetProperties(true))
                    {
                        ComFunctionInfo getComFunctionInfo = comPropertyInfo.GetFunction;
                        bool            bReadOnly          = comPropertyInfo.SetFunction == null ? true : false;

                        if (getComFunctionInfo != null)
                        {
                            VarEnum variantType = getComFunctionInfo.ReturnParameter.VariantType;

                            switch (variantType)
                            {
                            case VarEnum.VT_PTR:
                            case VarEnum.VT_DISPATCH:
                            case VarEnum.VT_UNKNOWN:
                                continue;

                            case VarEnum.VT_SAFEARRAY:
                                continue;
                            }

                            // Special case. MailSession is a PITA property that causes modal dialog.
                            if (comPropertyInfo.Name.Equals("MailSession"))
                            {
                                ComPtrProperty comPtrProperty = new ComPtrProperty(comPropertyInfo.Name, comPropertyInfo.Description, 0, typeof(int), variantType, true);
                                list.Add(new ComPtrPropertyDescriptor(ref comPtrProperty, comPropertyInfo, attributes));
                                continue;
                            }

                            object value = null;
                            if (MarshalEx.Succeeded(TryInvokePropertyGet(getComFunctionInfo.DispId, out value)))
                            {
                                Type propertyType = typeof(object);

                                if (value != null)
                                {
                                    propertyType = value.GetType();
                                }
                                else
                                {
                                    bReadOnly = true;
                                }

                                ComPtrProperty comPtrProperty = new ComPtrProperty(comPropertyInfo.Name, comPropertyInfo.Description, value, propertyType, variantType, bReadOnly);
                                list.Add(new ComPtrPropertyDescriptor(ref comPtrProperty, comPropertyInfo, attributes));
                            }
                        }
                    }

#if DEBUG
                    var refCountProperty = new ComPtrProperty("[RefCount]", "", this.RefCount, typeof(int), VarEnum.VT_I4, true);
                    list.Add(new ComPtrPropertyDescriptor(ref refCountProperty, null, attributes));
#endif
                    var pointerProperty = new ComPtrProperty("[Pointer]", "", this.handle, typeof(string), VarEnum.VT_INT, true);
                    list.Add(new ComPtrPropertyDescriptor(ref pointerProperty, null, attributes));

                    _propertyDescriptorCollection = new PropertyDescriptorCollection(list.ToArray());
                }
            }

            return(_propertyDescriptorCollection);
        }