public object Fetch(object obj)
        {
            if (this.innerFetcher == null)
            {
                this.innerFetcher = PropertyFetch.FetcherForProperty(obj.GetType().GetTypeInfo().GetDeclaredProperty(this.propertyName));
            }

            return(this.innerFetcher?.Fetch(obj));
        }
                /// <summary>
                /// Given an object fetch the property that this PropertySpec represents.
                /// </summary>
                public object Fetch(object obj)
                {
                    Type          objType = obj.GetType();
                    PropertyFetch fetch   = _fetchForExpectedType;

                    if (fetch == null || fetch.Type != objType)
                    {
                        _fetchForExpectedType = fetch = PropertyFetch.FetcherForProperty(
                            objType, objType.GetTypeInfo().GetDeclaredProperty(_propertyName));
                    }
                    return(fetch.Fetch(obj));
                }
Exemple #3
0
        /// <summary>
        /// Given an object fetch the property that this PropertySpec represents.
        /// </summary>
        public object Fetch(object obj)
        {
            Type objType = obj.GetType();

            if (_fetchForExpectedType == null)
            {
                TypeInfo     typeInfo     = objType.GetTypeInfo();
                PropertyInfo propertyInfo = typeInfo.GetProperty(_propertyName, DefaultBindingFlags);
                _fetchForExpectedType = PropertyFetch.FetcherForProperty(propertyInfo);
            }
            return(_fetchForExpectedType.Fetch(obj));
        }
Exemple #4
0
                /// <summary>
                /// Given an object fetch the property that this PropertySpec represents.
                /// </summary>
                public object Fetch(object obj)
                {
                    Type objType = obj.GetType();

                    if (objType != _expectedType)
                    {
                        var typeInfo = objType.GetTypeInfo();
                        _fetchForExpectedType = PropertyFetch.FetcherForProperty(typeInfo.GetDeclaredProperty(_propertyName));
                        _expectedType         = objType;
                    }
                    return(_fetchForExpectedType.Fetch(obj));
                }
Exemple #5
0
    /// <summary>
    /// Gets the value of the property on the specified object.
    /// </summary>
    /// <typeparam name="T">Type of the result.</typeparam>
    /// <param name="obj">The object that contains the property.</param>
    /// <param name="objType">Type of the object</param>
    /// <returns>The value of the property on the specified object.</returns>
    public T Fetch <T>(object obj, Type objType)
    {
        if (objType != _expectedType)
        {
            var propertyInfo = objType.GetProperty(_propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase);
            _fetchForExpectedType = PropertyFetch <T> .FetcherForProperty(propertyInfo);

            _expectedType = objType;
        }

        return(((PropertyFetch <T>)_fetchForExpectedType).Fetch(obj));
    }
Exemple #6
0
        public object Fetch(object obj)
        {
            PropertyFetch fetch   = this.innerFetcher;
            Type          objType = obj?.GetType();

            if (fetch == null || fetch.Type != objType)
            {
                this.innerFetcher = fetch = PropertyFetch.FetcherForProperty(objType, objType?.GetTypeInfo()?.GetDeclaredProperty(this.propertyName));
            }

            return(fetch?.Fetch(obj));
        }
        /// <summary>
        /// Given an object fetch the property that this PropertySpec represents.
        /// </summary>
        public object Fetch(object obj)
        {
            Type objType = obj.GetType();

            if (objType != _expectedType)
            {
                TypeInfo typeInfo     = objType.GetTypeInfo();
                var      propertyInfo = typeInfo.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, _propertyName, StringComparison.InvariantCultureIgnoreCase));
                _fetchForExpectedType = PropertyFetch.FetcherForProperty(propertyInfo);
                _expectedType         = objType;
            }
            return(_fetchForExpectedType.Fetch(obj));
        }
        /// <summary>
        /// Gets the value of the property on the specified object.
        /// </summary>
        /// <param name="obj">The object that contains the property.</param>
        /// <returns>The value of the property on the specified object.</returns>
        public object Fetch(object obj)
        {
            Type objType = obj.GetType();

            if (objType != _expectedType)
            {
                var propertyInfo = objType.GetProperty(_propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase);
                _fetchForExpectedType = PropertyFetch.FetcherForProperty(propertyInfo);
                _expectedType         = objType;
            }

            return(_fetchForExpectedType.Fetch(obj));
        }
Exemple #9
0
        public object Fetch(object obj)
        {
            if (this.innerFetcher == null)
            {
                var type     = obj.GetType().GetTypeInfo();
                var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, this.propertyName, StringComparison.InvariantCultureIgnoreCase));
                if (property == null)
                {
                    property = type.GetProperty(this.propertyName);
                }

                this.innerFetcher = PropertyFetch.FetcherForProperty(property);
            }

            return(this.innerFetcher?.Fetch(obj));
        }
        public object Fetch(object obj)
        {
            if (this.innerFetcher == null)
            {
                var type     = obj.GetType().GetTypeInfo();
                var property = type.GetDeclaredProperty(this.propertyName);
                if (property == null)
                {
                    property = type.GetProperty(this.propertyName);
                }

                this.innerFetcher = PropertyFetch.FetcherForProperty(property);
            }

            return(this.innerFetcher?.Fetch(obj));
        }
        public virtual object Fetch(object obj)
        {
            if (_innerFetcher == null)
            {
                var type     = obj.GetType().GetTypeInfo();
                var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, _propertyName, StringComparison.OrdinalIgnoreCase));
                if (property == null)
                {
                    property = type.GetProperty(_propertyName);
                }

                _innerFetcher = PropertyFetch.FetcherForProperty(property);
            }

            return(_innerFetcher?.Fetch(obj));
        }
Exemple #12
0
        /// <summary>
        /// Try to fetch the property from the object.
        /// </summary>
        /// <param name="obj">Object to be fetched.</param>
        /// <param name="value">Fetched value.</param>
        /// <param name="skipObjNullCheck">Set this to <see langword= "true"/> if we know <paramref name="obj"/> is not <see langword= "null"/>.</param>
        /// <returns><see langword= "true"/> if the property was fetched.</returns>
        public bool TryFetch(object obj, out T value, bool skipObjNullCheck = false)
        {
            if (!skipObjNullCheck && obj == null)
            {
                value = default;
                return(false);
            }

            if (this.innerFetcher == null)
            {
                var type     = obj.GetType().GetTypeInfo();
                var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, this.propertyName, StringComparison.InvariantCultureIgnoreCase));
                if (property == null)
                {
                    property = type.GetProperty(this.propertyName);
                }

                this.innerFetcher = PropertyFetch.FetcherForProperty(property);
            }

            return(this.innerFetcher.TryFetch(obj, out value));
        }
        /// <summary>
        /// Try to fetch the property from the object.
        /// </summary>
        /// <param name="obj">Object to be fetched.</param>
        /// <param name="value">Fetched value.</param>
        /// <returns><see langword="true"/> if the property was fetched.</returns>
        public bool TryFetch(object?obj, out T?value)
        {
            if (obj is null)
            {
                value = default;
                return(false);
            }

            if (_innerFetcher is null)
            {
                var type     = obj.GetType().GetTypeInfo();
                var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, _propertyName, StringComparison.InvariantCultureIgnoreCase));
                if (property is null)
                {
                    property = type.GetProperty(_propertyName);
                }

                _innerFetcher = PropertyFetch.FetcherForProperty(property);
            }

            return(_innerFetcher.TryFetch(obj, out value));
        }