示例#1
0
        private void OnPropsInfoDisposed(object sender, EventArgs e)
        {
            Com2Properties properties = sender as Com2Properties;

            if (properties != null)
            {
                properties.Disposed -= new EventHandler(this.OnPropsInfoDisposed);
                lock (this.nativeProps)
                {
                    object targetObject = properties.TargetObject;
                    if ((targetObject == null) && this.nativeProps.ContainsValue(properties))
                    {
                        foreach (DictionaryEntry entry in this.nativeProps)
                        {
                            if (entry.Value == properties)
                            {
                                targetObject = entry.Key;
                                break;
                            }
                        }
                        if (targetObject == null)
                        {
                            return;
                        }
                    }
                    this.nativeProps.Remove(targetObject);
                }
            }
        }
示例#2
0
        private Com2Properties GetPropsInfo(object component)
        {
            // check caches if necessary
            //
            CheckClear();

            // Get the property info Object
            //
            Com2Properties propsInfo = (Com2Properties)nativeProps[component];

            // if we don't have one, create one and set it up
            //
            if (propsInfo is null || !propsInfo.CheckValid())
            {
                propsInfo = Com2TypeInfoProcessor.GetProperties(component);
                if (propsInfo is not null)
                {
                    propsInfo.Disposed += new EventHandler(OnPropsInfoDisposed);
                    nativeProps.SetWeak(component, propsInfo);
                    propsInfo.AddExtendedBrowsingHandlers(extendedBrowsingHandlers);
                }
            }

            return(propsInfo);
        }
示例#3
0
        internal PropertyDescriptor GetDefaultProperty(object component)
        {
            this.CheckClear(component);
            Com2Properties propsInfo = this.GetPropsInfo(component);

            if (propsInfo != null)
            {
                return(propsInfo.DefaultProperty);
            }
            return(null);
        }
示例#4
0
        /// <include file='doc\ComNativeDescriptor.uex' path='docs/doc[@for="ComNativeDescriptor.GetProperties"]/*' />
        /// <devdoc>
        /// Props!
        /// </devdoc>
        public PropertyDescriptorCollection GetProperties(Object component, Attribute[] attributes)
        {
            Com2Properties propsInfo = GetPropsInfo(component);

            if (propsInfo == null)
            {
                return(PropertyDescriptorCollection.Empty);
            }

            try {
                propsInfo.AlwaysValid = true;
                ArrayList            propDescList = null;
                PropertyDescriptor[] props        = propsInfo.Properties;

                for (int i = 0; i < props.Length; i++)
                {
                    if (!props[i].Attributes.Contains(attributes))
                    {
                        if (propDescList == null)
                        {
                            propDescList = new ArrayList();

                            // add all the ones we've passed
                            if (i > 0)
                            {
                                // since I can't add a subrange!
                                for (int j = 0; j < i; j++)
                                {
                                    propDescList.Add(props[j]);
                                }
                            }
                        }
                        continue;
                    }
                    else if (propDescList != null)
                    {
                        propDescList.Add(props[i]);
                    }
                }

                if (propDescList != null)
                {
                    props = new PropertyDescriptor[propDescList.Count];
                    propDescList.CopyTo(props, 0);
                }

                //Debug.Assert(propDescList.Count > 0, "Didn't add any properties! (propInfos=0)");
                return(new PropertyDescriptorCollection(props));
            }
            finally {
                propsInfo.AlwaysValid = false;
            }
        }
示例#5
0
        /// <include file='doc\ComNativeDescriptor.uex' path='docs/doc[@for="ComNativeDescriptor.GetDefaultProperty"]/*' />
        /// <devdoc>
        /// Default Property, please
        /// </devdoc>
        public PropertyDescriptor GetDefaultProperty(Object component)
        {
            CheckClear(component);

            Com2Properties propsInfo = GetPropsInfo(component);

            if (propsInfo != null)
            {
                return(propsInfo.DefaultProperty);
            }
            return(null);
        }
示例#6
0
        private Com2Properties GetPropsInfo(object component)
        {
            this.CheckClear(component);
            Com2Properties properties = (Com2Properties)this.nativeProps[component];

            if ((properties == null) || !properties.CheckValid())
            {
                properties = Com2TypeInfoProcessor.GetProperties(component);
                if (properties != null)
                {
                    properties.Disposed += new EventHandler(this.OnPropsInfoDisposed);
                    this.nativeProps.SetWeak(component, properties);
                    properties.AddExtendedBrowsingHandlers(this.extendedBrowsingHandlers);
                }
            }
            return(properties);
        }
示例#7
0
        /// <summary>
        ///  Props!
        /// </summary>
        internal PropertyDescriptorCollection GetProperties(object component)
        {
            Com2Properties propsInfo = GetPropsInfo(component);

            if (propsInfo == null)
            {
                return(PropertyDescriptorCollection.Empty);
            }

            try
            {
                propsInfo.AlwaysValid = true;
                return(new PropertyDescriptorCollection(propsInfo.Properties));
            }
            finally
            {
                propsInfo.AlwaysValid = false;
            }
        }
示例#8
0
        internal PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes)
        {
            Com2Properties propsInfo = GetPropsInfo(component);

            if (propsInfo == null)
            {
                return(PropertyDescriptorCollection.Empty);
            }

            try {
                propsInfo.AlwaysValid = true;
                PropertyDescriptor[] props = propsInfo.Properties;

                //Debug.Assert(propDescList.Count > 0, "Didn't add any properties! (propInfos=0)");
                return(new PropertyDescriptorCollection(props));
            }
            finally {
                propsInfo.AlwaysValid = false;
            }
        }
示例#9
0
        internal PropertyDescriptorCollection GetProperties(object component, Attribute[] attributes)
        {
            PropertyDescriptorCollection descriptors;
            Com2Properties propsInfo = this.GetPropsInfo(component);

            if (propsInfo == null)
            {
                return(PropertyDescriptorCollection.Empty);
            }
            try
            {
                propsInfo.AlwaysValid = true;
                descriptors           = new PropertyDescriptorCollection(propsInfo.Properties);
            }
            finally
            {
                propsInfo.AlwaysValid = false;
            }
            return(descriptors);
        }
示例#10
0
        /// <devdoc>
        /// Fired when the property info gets disposed.
        /// </devdoc>
        private void OnPropsInfoDisposed(object sender, EventArgs e)
        {
            Com2Properties propsInfo = sender as Com2Properties;

            if (propsInfo != null)
            {
                propsInfo.Disposed -= new EventHandler(OnPropsInfoDisposed);

                lock (nativeProps) {
                    // find the key
                    object key = propsInfo.TargetObject;

                    if (key == null && nativeProps.ContainsValue(propsInfo))
                    {
                        // need to find it - the target object has probably been cleaned out
                        // of the Com2Properties object already, so we run through the
                        // hashtable looking for the value, so we know what key to remove.
                        //
                        foreach (DictionaryEntry de in nativeProps)
                        {
                            if (de.Value == propsInfo)
                            {
                                key = de.Key;
                                break;
                            }
                        }

                        if (key == null)
                        {
                            Debug.Fail("Failed to find Com2 properties key on dispose.");
                            return;
                        }
                    }

                    nativeProps.Remove(key);
                }
            }
        }
示例#11
0
        /// <include file='doc\ComNativeDescriptor.uex' path='docs/doc[@for="ComNativeDescriptor.GetPropsInfo"]/*' />
        /// <devdoc>
        /// Gets the properties manager for an Object.
        /// </devdoc>
        private Com2Properties GetPropsInfo(Object component)
        {
            // check caches if necessary
            //
            CheckClear(component);

            // Get the property info Object
            //
            Com2Properties propsInfo = (Com2Properties)nativeProps[component.GetHashCode()];

            // if we dont' have one, create one and set it up
            //
            if (propsInfo == null || !propsInfo.CheckValid())
            {
                propsInfo = Com2TypeInfoProcessor.GetProperties(component);
                if (propsInfo != null)
                {
                    propsInfo.AddToHashtable(nativeProps);
                    propsInfo.AddExtendedBrowsingHandlers(extendedBrowsingHandlers);
                }
            }
            return(propsInfo);
        }
示例#12
0
        /// <include file='doc\ComNativeDescriptor.uex' path='docs/doc[@for="ComNativeDescriptor.CheckClear"]/*' />
        /// <devdoc>
        /// Checks all our property manages to see if any have become invalid.
        /// </devdoc>
        private void CheckClear(Object component)
        {
            // walk the list every so many calls
            if ((++clearCount % CLEAR_INTERVAL) == 0)
            {
                lock (nativeProps) {
                    clearCount = 0;
                    // ArrayList   removeList = null;

                    ICollection      propValues = nativeProps.Values;
                    Com2Properties[] props      = new Com2Properties[propValues.Count];

                    propValues.CopyTo(props, 0);

                    for (int i = 0; i < props.Length; i++)
                    {
                        if (props[i].TooOld)
                        {
                            props[i].Dispose();
                        }
                    }
                }
            }
        }