Catel.Runtime.Serialization.SerializationManager.GetRegularPropertiesToSerialize C# (CSharp) Метод

GetRegularPropertiesToSerialize() публичный Метод

Gets the properties to serialize for the specified object.
The is null.
public GetRegularPropertiesToSerialize ( Type type ) : MemberMetadata>.Dictionary
type System.Type The type.
Результат MemberMetadata>.Dictionary
        public virtual Dictionary<string, MemberMetadata> GetRegularPropertiesToSerialize(Type type)
        {
            Argument.IsNotNull("type", type);

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

                var catelPropertyNames = new HashSet<string>();

                var isModelBase = type.IsModelBase();
                if (isModelBase)
                {
                    catelPropertyNames = GetCatelPropertyNames(type, true);
                }

                var regularProperties = GetRegularProperties(type);
                foreach (var typeProperty in regularProperties)
                {
                    var memberMetadata = typeProperty.Value;
                    var propertyInfo = (PropertyInfo)memberMetadata.Tag;

                    if (!catelPropertyNames.Contains(memberMetadata.MemberName))
                    {
                        // If not a ModelBase, include by default
                        var include = !isModelBase;

                        if (AttributeHelper.IsDecoratedWithAttribute<IncludeInSerializationAttribute>(propertyInfo))
                        {
                            include = true;
                        }

                        if (AttributeHelper.IsDecoratedWithAttribute<ExcludeFromSerializationAttribute>(propertyInfo))
                        {
                            include = false;
                        }

                        if (include)
                        {
                            serializableMembers.Add(typeProperty.Key, memberMetadata);
                        }
                    }
                }

                return serializableMembers;
            });
        }

Usage Example

Пример #1
0
            public void ReturnsCorrectProperties()
            {
                var serializationManager = new SerializationManager();

                var propertiesToSerialize = serializationManager.GetRegularPropertiesToSerialize(typeof(TestModel)).ToArray();

                Assert.AreEqual(1, propertiesToSerialize.Length);
                Assert.AreEqual("IncludedRegularProperty", propertiesToSerialize[0].Key);
            }
All Usage Examples Of Catel.Runtime.Serialization.SerializationManager::GetRegularPropertiesToSerialize