Catel.Runtime.Serialization.SerializationManager.GetCatelPropertiesToSerialize C# (CSharp) Method

GetCatelPropertiesToSerialize() public method

Gets the catel properties to serialize.
The is null.
public GetCatelPropertiesToSerialize ( Type type ) : MemberMetadata>.Dictionary
type System.Type The type.
return MemberMetadata>.Dictionary
        public virtual Dictionary<string, MemberMetadata> GetCatelPropertiesToSerialize(Type type)
        {
            Argument.IsNotNull("type", type);

            return _catelPropertiesToSerializeCache.GetFromCacheOrFetch(type, () =>
            {
                var serializableMembers = new Dictionary<string, MemberMetadata>();

                var properties = GetCatelProperties(type);
                foreach (var modelProperty in properties)
                {
                    var memberMetadata = modelProperty.Value;
                    var propertyData = (PropertyData)memberMetadata.Tag;

                    bool isSerializable = propertyData.IsSerializable || propertyData.Type.IsModelBase();
                    if (!isSerializable)
                    {
                        // CTL-550
                        var cachedPropertyInfo = propertyData.GetPropertyInfo(type);
                        if (AttributeHelper.IsDecoratedWithAttribute<IncludeInSerializationAttribute>(cachedPropertyInfo.PropertyInfo))
                        {
                            isSerializable = true;
                        }
                    }

                    if (!isSerializable)
                    {
                        Log.Warning("Property '{0}' is not serializable, so will be excluded from the serialization. If this property needs to be included, use the 'IncludeInSerializationAttribute'", propertyData.Name);
                        continue;
                    }

                    if (!propertyData.IncludeInSerialization)
                    {
                        Log.Debug("Property '{0}' is flagged to be excluded from serialization", propertyData.Name);
                        continue;
                    }

                    var propertyInfo = propertyData.GetPropertyInfo(type);
                    if (propertyInfo != null)
                    {
                        if (!AttributeHelper.IsDecoratedWithAttribute<ExcludeFromSerializationAttribute>(propertyInfo.PropertyInfo))
                        {
                            serializableMembers.Add(modelProperty.Key, memberMetadata);
                        }
                    }
                    else
                    {
                        // Dynamic property, always include
                        serializableMembers.Add(modelProperty.Key, memberMetadata);
                    }
                }

                return serializableMembers;
            });
        }

Usage Example

Example #1
0
            public void ThrowsArgumentNullExceptionForNullType()
            {
                var serializationManager = new SerializationManager();

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => serializationManager.GetCatelPropertiesToSerialize(null));
            }
All Usage Examples Of Catel.Runtime.Serialization.SerializationManager::GetCatelPropertiesToSerialize