internal DataItemPropertyDescriptorBase CreatePropertyDescriptor(PropertyDescriptor source)
        {
            if (!DataItemPropertyDescriptorFactory.IsReflected(source))
            {
                return(null);
            }

            var componentType = source.ComponentType;

            PropertyInfo propertyInfo;

            try
            {
                propertyInfo = componentType.GetProperty(source.Name, BindingFlags.Public | BindingFlags.Instance);
                if ((propertyInfo == null) || DataItemPropertyDescriptorFactory.IsIndexed(propertyInfo))
                {
                    return(null);
                }
            }
            catch (AmbiguousMatchException)
            {
                return(null);
            }

            var propertyType = propertyInfo.PropertyType;

            Debug.Assert(propertyType == source.PropertyType);

            var creatorHelper = DelegateCreatorHelperFactory.CreateHelper(componentType, propertyType);

            var getter = DataItemPropertyDescriptorFactory.CreateGetter(propertyInfo, creatorHelper);

            if (getter == null)
            {
                return(null);
            }

            var setter   = DataItemPropertyDescriptorFactory.CreateSetter(propertyInfo, creatorHelper);
            var resetter = DataItemPropertyDescriptorFactory.CreateResetter(componentType, propertyInfo, creatorHelper);

            var propertyChangedEvent = this.GetPropertyChangedEvent(propertyInfo.Name);

            if (propertyChangedEvent != null)
            {
                return(new ValueChangeDataItemPropertyDescriptor(m_typeDescriptor, source, componentType, propertyType, getter, setter, resetter, propertyChangedEvent));
            }

            return(new DataItemPropertyDescriptor(m_typeDescriptor, source, componentType, propertyType, getter, setter, resetter));
        }
        internal DataItemEventDescriptorBase CreateEventDescriptor(EventDescriptor source)
        {
            if (!DataItemEventDescriptorFactory.IsReflected(source))
            {
                return(null);
            }

            var componentType = source.ComponentType;

            EventInfo eventInfo;

            try
            {
                eventInfo = componentType.GetEvent(source.Name, BindingFlags.Public | BindingFlags.Instance);
                if (eventInfo == null)
                {
                    return(null);
                }
            }
            catch (AmbiguousMatchException)
            {
                return(null);
            }

            var handlerType = eventInfo.EventHandlerType;

            Debug.Assert(handlerType == source.EventType);

            var creatorHelper = DelegateCreatorHelperFactory.CreateHelper(componentType, handlerType);

            var addHandler = DataItemEventDescriptorFactory.CreateAddHandler(eventInfo, creatorHelper);

            if (addHandler == null)
            {
                return(null);
            }

            var removeHandler = DataItemEventDescriptorFactory.CreateRemoveHandler(eventInfo, creatorHelper);

            if (removeHandler == null)
            {
                return(null);
            }

            return(new DataItemEventDescriptor(m_typeDescriptor, source, componentType, handlerType, addHandler, removeHandler));
        }