Esempio n. 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(Polenter.Serialization.Serializing.TypeInfo info, PropertyInfo property)
        {
            // Soll die Eigenschaft ignoriert werden
            if (this.PropertiesToIgnore.Contains(info.Type, property.Name))
            {
                return(true);
            }

            if (this.ContainsExcludeFromSerializationAttribute(property))
            {
                return(true);
            }

            if (!property.CanRead || !property.CanWrite)
            {
                return(true);
            }

            ParameterInfo[] indexParameters = property.GetIndexParameters();
            if (indexParameters.Length > 0)
            {
                // Indexer
                return(true);
            }

            return(false);
        }
Esempio n. 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(Polenter.Serialization.Serializing.TypeInfo typeInfo)
        {
            // Search in cache
            var propertyInfos = Cache.TryGetPropertyInfos(typeInfo.Type);

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

            // Creating infos
            PropertyInfo[] properties = this.GetAllProperties(typeInfo.Type);
            var            result     = new List <PropertyInfo>();

            foreach (PropertyInfo property in properties)
            {
                if (!this.IgnoreProperty(typeInfo, property))
                {
                    result.Add(property);
                }
            }

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

            return(result);
        }