System.ComponentModel.PropertyDescriptorCollection.Find C# (CSharp) Method

Find() public method

public Find ( string name, bool ignoreCase ) : PropertyDescriptor
name string
ignoreCase bool
return PropertyDescriptor
        public virtual PropertyDescriptor Find(string name, bool ignoreCase) {
            lock(this) {
                PropertyDescriptor p = null;

                if (cachedFoundProperties == null || cachedIgnoreCase != ignoreCase) {
                    cachedIgnoreCase = ignoreCase;
                    cachedFoundProperties = new HybridDictionary(ignoreCase);
                }
                
                // first try to find it in the cache
                //
                object cached = cachedFoundProperties[name];
                
                if (cached != null) {
                    return (PropertyDescriptor) cached;
                }
                
                // Now start walking from where we last left off, filling
                // the cache as we go.
                //
                for(int i = 0; i < propCount; i++) {
                    
                    if (ignoreCase) {
                        if (String.Equals(properties[i].Name, name, StringComparison.OrdinalIgnoreCase)) {
                            cachedFoundProperties[name] = properties[i];
                            p = properties[i];
                            break;
                        }
                    }
                    else {
                        if (properties[i].Name.Equals(name)) {
                            cachedFoundProperties[name] = properties[i];
                            p = properties[i];
                            break;
                        }
                    }
                }
                
                return p;
            }
        }
        

Usage Example

        public static void AddGraphicProperties(List<PropertyDescriptor> allProperties,
		                                         PropertyDescriptorCollection props)
        {
            PropertyDescriptor prop = null;
            prop = props.Find("ForeColor",true);
            allProperties.Add(prop);

            prop = props.Find("DashStyle",true);
            allProperties.Add(prop);

            prop = props.Find("Thickness",true);
            allProperties.Add(prop);
        }
All Usage Examples Of System.ComponentModel.PropertyDescriptorCollection::Find