コード例 #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(TypeInfo info, PropertyInfo property)
        {
            // Soll die Eigenschaft ignoriert werden
            if (PropertiesToIgnore.Contains(info.Type, property.Name))
            {
                return(true);
            }

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

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

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

            return(false);
        }
コード例 #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(TypeInfo typeInfo)
        {
            // Search in cache
            var propertyInfos = Cache.TryGetPropertyInfos(typeInfo.Type);

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

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

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

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

            return(result);
        }
コード例 #3
0
        private void parseSingleDimensionalArrayProperty(SingleDimensionalArrayProperty property)
        {
            // ElementType
            property.ElementType = property.Type != null?TypeInfo.GetTypeInfo(property.Type).ElementType : null;

            // LowerBound
            property.LowerBound = _reader.GetAttributeAsInt(Attributes.LowerBound);

            // Items
            foreach (string subElement in _reader.ReadSubElements())
            {
                if (subElement == SubElements.Items)
                {
                    readItems(property.Items, property.ElementType);
                }
            }
        }
コード例 #4
0
        private void parseMultiDimensionalArrayProperty(MultiDimensionalArrayProperty property)
        {
            property.ElementType = property.Type != null?TypeInfo.GetTypeInfo(property.Type).ElementType : null;

            foreach (string subElement in _reader.ReadSubElements())
            {
                if (subElement == SubElements.Dimensions)
                {
                    // Read dimensions
                    readDimensionInfos(property.DimensionInfos);
                }

                if (subElement == SubElements.Items)
                {
                    // Read items
                    readMultiDimensionalArrayItems(property.Items, property.ElementType);
                }
            }
        }
コード例 #5
0
        private void parseCollectionProperty(CollectionProperty property)
        {
            // ElementType
            property.ElementType = property.Type != null?TypeInfo.GetTypeInfo(property.Type).ElementType : null;

            foreach (string subElement in _reader.ReadSubElements())
            {
                if (subElement == SubElements.Properties)
                {
                    // Properties
                    readProperties(property.Properties, property.Type);
                    continue;
                }

                if (subElement == SubElements.Items)
                {
                    // Items
                    readItems(property.Items, property.ElementType);
                }
            }
        }
コード例 #6
0
        private void parseDictionaryProperty(DictionaryProperty property)
        {
            if (property.Type != null)
            {
                var typeInfo = TypeInfo.GetTypeInfo(property.Type);
                property.KeyType   = typeInfo.KeyType;
                property.ValueType = typeInfo.ElementType;
            }

            foreach (string subElement in _reader.ReadSubElements())
            {
                if (subElement == SubElements.Properties)
                {
                    // Properties
                    readProperties(property.Properties, property.Type);
                    continue;
                }
                if (subElement == SubElements.Items)
                {
                    // Items
                    readDictionaryItems(property.Items, property.KeyType, property.ValueType);
                }
            }
        }