GetRegularPropertiesToSerialize() public méthode

Gets the properties to serialize for the specified object.
The is null.
public GetRegularPropertiesToSerialize ( Type type ) : MemberMetadata>.Dictionary
type System.Type The type.
Résultat MemberMetadata>.Dictionary
            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);
            }
        /// <summary>
        /// Gets the serializable members for the specified model.
        /// </summary>
        /// <param name="context">The serialization context.</param>
        /// <param name="model">The model.</param>
        /// <param name="membersToIgnore">The members to ignore.</param>
        /// <returns>The list of members to serialize.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="model"/> is <c>null</c>.</exception>
        public virtual List <MemberValue> GetSerializableMembers(ISerializationContext <TSerializationContext> context, object model, params string[] membersToIgnore)
        {
            Argument.IsNotNull("model", model);

            var listToSerialize        = new List <MemberValue>();
            var membersToIgnoreHashSet = new HashSet <string>(membersToIgnore);

            var modelType = model.GetType();

            // If a basic type, we need to directly deserialize as member and replace the context model
            if (ShouldExternalSerializerHandleMember(context.ModelType))
            {
                listToSerialize.Add(new MemberValue(SerializationMemberGroup.SimpleRootObject, modelType, modelType, RootObjectName, RootObjectName, model));
                return(listToSerialize);
            }

            if (ShouldSerializeAsDictionary(modelType))
            {
                // CTL-688: only support json for now. In the future, these checks (depth AND type) should be removed
                if (SupportsDictionarySerialization(context))
                {
                    listToSerialize.Add(new MemberValue(SerializationMemberGroup.Dictionary, modelType, modelType, CollectionName, CollectionName, model));
                    return(listToSerialize);
                }
            }

            if (ShouldSerializeAsCollection(modelType))
            {
                listToSerialize.Add(new MemberValue(SerializationMemberGroup.Collection, modelType, modelType, CollectionName, CollectionName, model));
                return(listToSerialize);
            }

            if (modelType == typeof(SerializableKeyValuePair))
            {
                var keyValuePair = (SerializableKeyValuePair)model;

                var keyType   = typeof(object);
                var valueType = typeof(object);

                // Search max 2 levels deep, if not found, then we failed
                var parentDictionary = context.FindParentType(x => x.IsDictionary(), 2);
                if (parentDictionary != null)
                {
                    var genericTypeDefinition = parentDictionary.GetGenericArgumentsEx();

                    keyType   = genericTypeDefinition[0];
                    valueType = genericTypeDefinition[1];
                }

                listToSerialize.Add(new MemberValue(SerializationMemberGroup.RegularProperty, modelType, keyType, "Key", "Key", keyValuePair.Key));
                listToSerialize.Add(new MemberValue(SerializationMemberGroup.RegularProperty, modelType, valueType, "Value", "Value", keyValuePair.Value));

                return(listToSerialize);
            }

            var modelInfo = _serializationModelCache.GetFromCacheOrFetch(modelType, () =>
            {
                var catelProperties = SerializationManager.GetCatelPropertiesToSerialize(modelType);
                var fields          = SerializationManager.GetFieldsToSerialize(modelType);
                var properties      = SerializationManager.GetRegularPropertiesToSerialize(modelType);

                return(new SerializationModelInfo(modelType, catelProperties, fields, properties));
            });

            var members = new List <MemberMetadata>();

            members.AddRange(modelInfo.CatelPropertiesByName.Values);
            members.AddRange(modelInfo.PropertiesByName.Values);
            members.AddRange(modelInfo.FieldsByName.Values);

            foreach (var memberMetadata in members)
            {
                var memberName = memberMetadata.MemberName;
                if (membersToIgnoreHashSet.Contains(memberName) || ShouldIgnoreMember(model, memberName))
                {
                    Log.Debug("Member '{0}' is being ignored for serialization", memberName);
                    continue;
                }

                var memberValue = ObjectAdapter.GetMemberValue(model, memberName, modelInfo);
                if (memberValue != null)
                {
                    listToSerialize.Add(memberValue);
                }
            }

            return(listToSerialize);
        }
            public void ThrowsArgumentNullExceptionForNullType()
            {
                var serializationManager = new SerializationManager();

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => serializationManager.GetRegularPropertiesToSerialize(null));
            }