コード例 #1
0
 public ComPtrPropertyDescriptor(ref ComPtrProperty comPtrProperty, ComPropertyInfo comPropertyInfo, Attribute[] attrs)
     : base(comPtrProperty.Name, attrs)
 {
     _comPtrProperty  = comPtrProperty;
     _comPropertyInfo = comPropertyInfo;
 }
コード例 #2
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);
        }