Example #1
0
        /// <summary>
        ///     Should the property be removed from serialization?
        /// </summary>
        /// <param name="info"></param>
        /// <param name="property"></param>
        /// <returns>
        ///     true if the property:
        ///     - is in the PropertiesToIgnore,
        ///     - contains ExcludeFromSerializationAttribute,
        ///     - does not have it's set or get accessor
        ///     - is indexer
        /// </returns>
        protected virtual bool IgnoreProperty(InternalTypeInfo info, PropertyInfo property)
        {
            if (!property.CanRead || !property.CanWrite)
            {
                return(true);
            }

            var indexParameters = property.GetIndexParameters(); // remove indexer

            if (indexParameters.Length > 0)
            {
                return(true);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        ///     Gives all properties back which:
        ///     - are public
        ///     - are not static
        ///     - does not contain ExcludeFromSerializationAttribute
        ///     - have their set and get accessors
        ///     - are not indexers
        /// </summary>
        /// <param name="typeInfo"></param>
        /// <returns></returns>
        public IList <PropertyInfo> GetProperties(InternalTypeInfo typeInfo)
        {
            // Search in cache
            var propertyInfos = Cache.TryGetPropertyInfos(typeInfo.Type);

            if (propertyInfos != null)
            {
                return(propertyInfos);
            }

            // Creating infos
            var properties = GetAllProperties(typeInfo.Type);
            var result     = properties
                             .Where(property => !IgnoreProperty(typeInfo, property))
                             .ToList();

            // adding result to Cache
            Cache.Add(typeInfo.Type, result);

            return(result);
        }