Пример #1
0
            public PropertyDescriptor GetPropertyDescriptor(object source, string propertyName)
            {
                TypePropertyPair key = new TypePropertyPair()
                {
                    type = source != null?source.GetType() : null, propertyName = propertyName
                };

                if (key.type == null || key.propertyName == null)
                {
                    return(null);
                }
                if (cache.ContainsKey(key))
                {
                    return(cache[key]);
                }
                else
                {
                    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(source);
                    PropertyDescriptor           descriptor = properties == null ? null : properties.Find(propertyName, ignoreCase: true);
                    if (descriptor == null)
                    {
                        return(null);
                    }

                    lock (cache)
                    {
                        if (!cache.ContainsKey(key))
                        {
                            cache.Add(key, descriptor);
                        }
                    }
                    return(descriptor);
                }
            }
Пример #2
0
            public PropertyDescriptor GetPropertyDescriptor(object source, string propertyName)
            {
                TypePropertyPair key = new TypePropertyPair() { type = source != null ? source.GetType() : null, propertyName = propertyName };
                if (key.type == null || key.propertyName == null)
                    return null;
                if (cache.ContainsKey(key))
                    return cache[key];
                else
                {
                    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(source);
                    PropertyDescriptor descriptor = properties == null ? null : properties.Find(propertyName, ignoreCase: true);
                    if (descriptor == null) return null;

                    lock (cache)
                    {
                        if (!cache.ContainsKey(key))
                            cache.Add(key, descriptor);
                    }
                    return descriptor;
                }
            }