コード例 #1
0
        /// <summary>
        /// Creates a new instance of a DynamicPropertyReader
        /// </summary>
        /// <param name="sourceType">The assembly qualified name of the type against which the property should be invoked</param>
        /// <param name="propertyName">The name of the property to be 'gotten' and evaluated against</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the sourceType or propertyName arguments are null or empty strings</exception>
        /// <exception cref="System.TypeLoadException">Thrown if the sourceType is not a valid .NET type, or cannot be loaded</exception>
        public DynamicPropertyReader(string sourceType, string propertyName)
        {
            if (string.IsNullOrEmpty(sourceType))
                throw new ArgumentNullException("sourceType");
            if (string.IsNullOrEmpty(propertyName))
                throw new ArgumentNullException("propertyName");

            // Attmpt to get the type, and throw a TypeLoadException if not found
            Type type = Type.GetType(sourceType, true);

            _fastPropertyGetter = new FastPropertyGetter(propertyName, type);

            if (_fastPropertyGetter.PropertyType == typeof (string))
            {
                _comparator = StringComparator.Instance;
            }
            else if (typeof (IConvertible).IsAssignableFrom(_fastPropertyGetter.PropertyType) &&
                     typeof (IComparable).IsAssignableFrom(_fastPropertyGetter.PropertyType))
            {
                _comparator = NumericComparator.Instance;
            }
            else
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  Resources.DoesNotImplementRightInterfaces,
                                                                  propertyName, sourceType));
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of a DynamicPropertyReader
        /// </summary>
        /// <param name="sourceType">The assembly qualified name of the type against which the property should be invoked</param>
        /// <param name="propertyName">The name of the property to be 'gotten' and evaluated against</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the sourceType or propertyName arguments are null or empty strings</exception>
        /// <exception cref="System.TypeLoadException">Thrown if the sourceType is not a valid .NET type, or cannot be loaded</exception>
        public DynamicPropertyReader(string sourceType, string propertyName)
        {
            if (string.IsNullOrEmpty(sourceType))
            {
                throw new ArgumentNullException("sourceType");
            }
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            // Attmpt to get the type, and throw a TypeLoadException if not found
            Type type = Type.GetType(sourceType, true);

            _fastPropertyGetter = new FastPropertyGetter(propertyName, type);

            if (_fastPropertyGetter.PropertyType == typeof(string))
            {
                _comparator = StringComparator.Instance;
            }
            else if (typeof(IConvertible).IsAssignableFrom(_fastPropertyGetter.PropertyType) &&
                     typeof(IComparable).IsAssignableFrom(_fastPropertyGetter.PropertyType))
            {
                _comparator = NumericComparator.Instance;
            }
            else
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  Resources.DoesNotImplementRightInterfaces,
                                                                  propertyName, sourceType));
            }
        }
コード例 #3
0
        /// <summary>
        /// Contructs a new instance of the FastPropertyReader
        /// </summary>
        /// <param name="wrappedPropertyReader">The <see cref="PropertyReader"/> to be wrapped</param>
        /// <param name="propertyName">The name of the property to be retrieved from the result</param>
        public FastPropertyReader(PropertyReader wrappedPropertyReader, string propertyName)
        {
            _fastPropertyGetter = new FastPropertyGetter(propertyName, wrappedPropertyReader.PropertyType);
            _wrappedPropertyReader = wrappedPropertyReader;

            if (_fastPropertyGetter.PropertyType == typeof(string))
            {
                _comparator = StringComparator.Instance;
            }
            else if (typeof(IConvertible).IsAssignableFrom(_fastPropertyGetter.PropertyType) &&
                     typeof(IComparable).IsAssignableFrom(_fastPropertyGetter.PropertyType))
            {
                _comparator = NumericComparator.Instance;
            }
            else
            {
                _comparator = ObjectComparator.Instance;
            }
        }
コード例 #4
0
        /// <summary>
        /// Contructs a new instance of the FastPropertyReader
        /// </summary>
        /// <param name="wrappedPropertyReader">The <see cref="PropertyReader"/> to be wrapped</param>
        /// <param name="propertyName">The name of the property to be retrieved from the result</param>
        public FastPropertyReader(PropertyReader wrappedPropertyReader, string propertyName)
        {
            _fastPropertyGetter    = new FastPropertyGetter(propertyName, wrappedPropertyReader.PropertyType);
            _wrappedPropertyReader = wrappedPropertyReader;

            if (_fastPropertyGetter.PropertyType == typeof(string))
            {
                _comparator = StringComparator.Instance;
            }
            else if (typeof(IConvertible).IsAssignableFrom(_fastPropertyGetter.PropertyType) &&
                     typeof(IComparable).IsAssignableFrom(_fastPropertyGetter.PropertyType))
            {
                _comparator = NumericComparator.Instance;
            }
            else
            {
                _comparator = ObjectComparator.Instance;
            }
        }