/// <summary> /// Default ctor. /// </summary> public Com2Properties(object obj, Com2PropertyDescriptor[] props, int defaultIndex) { #if DEBUG ComNativeDescriptor cnd = new ComNativeDescriptor(); dbgObjName = cnd.GetName(obj); if (dbgObjName == null) { dbgObjName = "(null)"; } dbgObjClass = cnd.GetClassName(obj); if (dbgObjClass == null) { dbgObjClass = "(null)"; } if (DbgCom2PropertiesSwitch.TraceVerbose) { Debug.WriteLine("Creating Com2Properties for object " + dbgObjName + ", class=" + dbgObjClass); } #endif // set up our variables SetProps(props); weakObjRef = new WeakReference(obj); this.defaultIndex = defaultIndex; typeInfoVersions = GetTypeInfoVersions(obj); touchedTime = DateTime.Now.Ticks; }
/// <summary> /// Converts the given object to another type. The most common types to convert /// are to and from a string object. The default implementation will make a call /// to ToString on the object if the object is valid and if the destination /// type is string. If this cannot convert to the destination type, this will /// throw a NotSupportedException. /// </summary> public override object?ConvertTo(ITypeDescriptorContext?context, CultureInfo?culture, object?value, Type destinationType) { if (destinationType == typeof(string)) { if (value is null) { return(s_none); } string text = ComNativeDescriptor.GetName(value); if (text is null || text.Length == 0) { text = ComNativeDescriptor.GetClassName(value); } if (text is null) { return("(Object)"); } return(text); } return(base.ConvertTo(context, culture, value, destinationType)); }
/// <include file='doc\COM2Properties.uex' path='docs/doc[@for="Com2Properties.Com2Properties"]/*' /> /// <devdoc> /// Default ctor. /// </devdoc> public Com2Properties(object obj, Com2PropertyDescriptor[] props, int defaultIndex) { #if DEBUG ComNativeDescriptor cnd = new ComNativeDescriptor(); this.dbgObjName = cnd.GetName(obj); if (this.dbgObjName == null) { this.dbgObjName = "(null)"; } this.dbgObjClass = cnd.GetClassName(obj); if (this.dbgObjClass == null) { this.dbgObjClass = "(null)"; } if (DbgCom2PropertiesSwitch.TraceVerbose) { Debug.WriteLine("Creating Com2Properties for object " + dbgObjName + ", class=" + dbgObjClass); } #endif // set up our variables SetProps(props); weakObjRef = new WeakReference(obj); hashCode = obj.GetHashCode(); this.defaultIndex = defaultIndex; // get the type infos count if (obj is NativeMethods.IProvideMultipleClassInfo) { int infos = 0; if (NativeMethods.Succeeded(((NativeMethods.IProvideMultipleClassInfo)obj).GetMultiTypeInfoCount(ref infos))) { this.nTypeInfos = infos; } } }
/// <summary> /// ICustomTypeDescriptor implementation. /// </summary> string ICustomTypeDescriptor.GetClassName() { return(_handler.GetClassName(_instance)); }
private static PropInfo ProcessDataCore(UnsafeNativeMethods.ITypeInfo typeInfo, IDictionary propInfoList, int dispid, int nameDispID, System.Windows.Forms.NativeMethods.tagTYPEDESC typeDesc, int flags, StructCache structCache) { string pBstrName = null; string pBstrDocString = null; int hr = typeInfo.GetDocumentation(dispid, ref pBstrName, ref pBstrDocString, null, null); ComNativeDescriptor instance = ComNativeDescriptor.Instance; if (!System.Windows.Forms.NativeMethods.Succeeded(hr)) { throw new COMException(System.Windows.Forms.SR.GetString("TYPEINFOPROCESSORGetDocumentationFailed", new object[] { dispid, hr, instance.GetClassName(typeInfo) }), hr); } if (pBstrName == null) { return(null); } PropInfo info = (PropInfo)propInfoList[pBstrName]; if (info == null) { info = new PropInfo { Index = propInfoList.Count }; propInfoList[pBstrName] = info; info.Name = pBstrName; info.DispId = dispid; info.Attributes.Add(new DispIdAttribute(info.DispId)); } if (pBstrDocString != null) { info.Attributes.Add(new DescriptionAttribute(pBstrDocString)); } if (info.ValueType == null) { object[] typeData = new object[1]; try { info.ValueType = GetValueTypeFromTypeDesc(typeDesc, typeInfo, typeData, structCache); } catch (Exception) { } if (info.ValueType == null) { info.NonBrowsable = true; } if (info.NonBrowsable) { flags |= 0x400; } if (typeData[0] != null) { info.TypeData = typeData[0]; } } if ((flags & 1) != 0) { info.ReadOnly = 1; } if ((((flags & 0x40) != 0) || ((flags & 0x400) != 0)) || ((info.Name[0] == '_') || (dispid == -515))) { info.Attributes.Add(new BrowsableAttribute(false)); info.NonBrowsable = true; } if ((flags & 0x200) != 0) { info.IsDefault = true; } if (((flags & 4) != 0) && ((flags & 0x10) != 0)) { info.Attributes.Add(new BindableAttribute(true)); } if (dispid == nameDispID) { info.Attributes.Add(new ParenthesizePropertyNameAttribute(true)); info.Attributes.Add(new MergablePropertyAttribute(false)); } return(info); }
/// <include file='doc\COM2Properties.uex' path='docs/doc[@for="Com2Properties.Com2Properties"]/*' /> /// <devdoc> /// Default ctor. /// </devdoc> public Com2Properties(object obj, Com2PropertyDescriptor[] props, int defaultIndex) { #if DEBUG ComNativeDescriptor cnd = new ComNativeDescriptor(); this.dbgObjName = cnd.GetName(obj); if (this.dbgObjName == null) { this.dbgObjName = "(null)"; } this.dbgObjClass = cnd.GetClassName(obj); if (this.dbgObjClass == null) { this.dbgObjClass = "(null)"; } if (DbgCom2PropertiesSwitch.TraceVerbose) Debug.WriteLine("Creating Com2Properties for object " + dbgObjName + ", class=" + dbgObjClass); #endif // set up our variables SetProps(props); weakObjRef = new WeakReference(obj); this.defaultIndex = defaultIndex; typeInfoVersions = GetTypeInfoVersions(obj); touchedTime = DateTime.Now.Ticks; }
private unsafe void OnGetTypeConverterAndTypeEditor(Com2PropertyDescriptor sender, GetTypeConverterAndTypeEditorEvent gveevent) { if (sender.TargetObject is not Oleaut32.IPerPropertyBrowsing ppb) { return; } // check for enums Ole32.CALPOLESTR caStrings = default; Ole32.CADWORD caCookies = default; HRESULT hr; try { hr = ppb.GetPredefinedStrings(sender.DISPID, &caStrings, &caCookies); } catch (ExternalException ex) { hr = (HRESULT)ex.ErrorCode; Debug.Fail($"An exception occurred inside IPerPropertyBrowsing::GetPredefinedStrings(dispid={sender.DISPID}), object type={ComNativeDescriptor.GetClassName(ppb)}"); } // Terminate the existing editor if we created the current one so if the items have disappeared, // we don't hold onto the old items. if (gveevent.TypeConverter is Com2IPerPropertyEnumConverter) { gveevent.TypeConverter = null; } if (hr == HRESULT.S_OK) { string?[] names = caStrings.ConvertAndFree(); uint[] cookies = caCookies.ConvertAndFree(); if (names.Length > 0 && cookies.Length > 0) { gveevent.TypeConverter = new Com2IPerPropertyEnumConverter(new Com2IPerPropertyBrowsingEnum(sender, names, cookies)); } } else { // If we didn't get any strings, try the proppage editor // // This is a bit of a backwards-compat work around. Many older ActiveX controls will show a // property page for all properties since the old grid would only put up the [...] button for // "(Custom)". If we have a conversion editor, don't allow this to override it. if (sender.ConvertingNativeType) { return; } Guid guid = GetPropertyPageGuid(ppb, sender.DISPID); if (!Guid.Empty.Equals(guid)) { gveevent.TypeEditor = new Com2PropertyPageUITypeEditor(sender, guid, (UITypeEditor)gveevent.TypeEditor); } } }