Beispiel #1
0
 private static FastProperty[] GetFastPropertiesFor(Type type)
 {
     return FastProperty.GetProperties(type, PropertyCachingStrategy.Uncached)
         .Values
         .Where(pi => pi.IsPublicSettable)
         .ToArray();
 }
Beispiel #2
0
        /// <summary>
        /// Checks whether a property exists in the Property collection
        /// or as a property on the instance
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="includeInstanceProperties"></param>
        /// <returns></returns>
        public bool Contains(string propertyName, bool includeInstanceProperties = false)
        {
            if (Properties.ContainsKey(propertyName))
            {
                return(true);
            }

            if (includeInstanceProperties && _instance != null)
            {
                return(FastProperty.GetProperties(_instance).ContainsKey(propertyName));
            }

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Returns all properties
        /// </summary>
        /// <param name="includeInstanceProperties"></param>
        /// <returns></returns>
        public IEnumerable <KeyValuePair <string, object> > GetProperties(bool includeInstanceProperties = false)
        {
            foreach (var key in this.Properties.Keys)
            {
                yield return(new KeyValuePair <string, object>(key, this.Properties[key]));
            }

            if (includeInstanceProperties && _instance != null)
            {
                foreach (var prop in FastProperty.GetProperties(_instance).Values)
                {
                    if (!this.Properties.ContainsKey(prop.Name))
                    {
                        yield return(new KeyValuePair <string, object>(prop.Name, prop.GetValue(_instance)));
                    }
                }
            }
        }
Beispiel #4
0
        private IDictionary <string, FastProperty> GetInstanceProperties()
        {
            if (_instance == null)
            {
                return(EmptyProps);
            }

            if (_instanceProps == null)
            {
                var props = FastProperty.GetProperties(_instance) as IDictionary <string, FastProperty>;

                if (_optMembers != null)
                {
                    props = props
                            .Where(x => _optMethod == MemberOptMethod.Allow ? _optMembers.Contains(x.Key) : !_optMembers.Contains(x.Key))
                            .ToDictionary(x => x.Key, x => x.Value);
                }

                _instanceProps = props;
            }

            return(_instanceProps);
        }