Пример #1
0
        public PropertyAccessor GetPropertyAccessor(Type sourceType, string propertyName)
        {
            // check if accessor exists
            PropertyAccessor accessor;

            if (propertyAccessorDictionary.TryGetValue(sourceType, propertyName, out accessor))
            {
                // just return it
                return(accessor);
            }

            // get property info
            var propertyInfo = sourceType.GetProperty(propertyName);

            if (propertyInfo == null)
            {
                // invalid property name
                return(null);
            }

            // create new accessor
            accessor = new PropertyAccessor(propertyInfo);

            // add it
            propertyAccessorDictionary.Add(sourceType, propertyName, accessor);

            return(accessor);
        }
Пример #2
0
        /// <summary>
        /// Get a general converter
        /// </summary>
        /// <param name="sourceType">The source type to find</param>
        /// <param name="targetType">The target type to find</param>
        /// <returns>Return the converter if found, otherwise return null</returns>
        public IValueConverter GetConverter(Type sourceType, Type targetType)
        {
            if (typeDictionary.Count == 0)
            {
                return(null);
            }

            // get converter
            IValueConverter converter = null;

            if (!typeDictionary.TryGetValue(sourceType, targetType, out converter))
            {
                return(null);
            }

            return(converter);
        }