GetCatelProperties() 공개 메소드

Gets the catel properties.
The is null.
public GetCatelProperties ( Type type, bool includeModelBaseProperties = false ) : MemberMetadata>.Dictionary
type System.Type Type of the model.
includeModelBaseProperties bool if set to true, also include model base properties.
리턴 MemberMetadata>.Dictionary
예제 #1
0
        /// <summary>
        /// Gets the type of the member.
        /// </summary>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <returns>The <see cref="Type"/> of the member.</returns>
        protected Type GetMemberType(Type modelType, string memberName)
        {
            var catelProperties = SerializationManager.GetCatelProperties(modelType);

            if (catelProperties.ContainsKey(memberName))
            {
                return(catelProperties[memberName].MemberType);
            }

            var regularProperties = SerializationManager.GetRegularProperties(modelType);

            if (regularProperties.ContainsKey(memberName))
            {
                return(regularProperties[memberName].MemberType);
            }

            var fields = SerializationManager.GetFields(modelType);

            if (fields.ContainsKey(memberName))
            {
                return(fields[memberName].MemberType);
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Gets the type of the member.
        /// </summary>
        /// <param name="modelType">Type of the model.</param>
        /// <param name="memberName">Name of the member.</param>
        /// <returns>The <see cref="Type"/> of the member.</returns>
        protected Type GetMemberType(Type modelType, string memberName)
        {
            var catelProperties = SerializationManager.GetCatelProperties(modelType);

            if (catelProperties.TryGetValue(memberName, out var catelProperty))
            {
                return(catelProperty.MemberType);
            }

            var regularProperties = SerializationManager.GetRegularProperties(modelType);

            if (regularProperties.TryGetValue(memberName, out var regularProperty))
            {
                return(regularProperty.MemberType);
            }

            var fields = SerializationManager.GetFields(modelType);

            if (fields.TryGetValue(memberName, out var field))
            {
                return(field.MemberType);;
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Populates the model with the specified members.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="members">The members.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="model"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="members"/> is <c>null</c>.</exception>
        protected virtual void PopulateModel(object model, params MemberValue[] members)
        {
            Argument.IsNotNull("model", model);
            Argument.IsNotNull("properties", members);

            var modelType = model.GetType();

            var modelInfo = _serializationModelCache.GetFromCacheOrFetch(modelType, () =>
            {
                var catelProperties   = SerializationManager.GetCatelProperties(modelType);
                var fields            = SerializationManager.GetFields(modelType);
                var regularProperties = SerializationManager.GetRegularProperties(modelType);

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

            foreach (var member in members)
            {
                ObjectAdapter.SetMemberValue(model, member, modelInfo);
            }
        }
예제 #4
0
            public void ReturnsCorrectValue()
            {
                var serializationManager = new SerializationManager();

                var properties = serializationManager.GetCatelProperties(typeof(TestModel)).ToArray();

                Assert.AreEqual(3, properties.Length);
                Assert.AreEqual("IncludedCatelProperty", properties[0].Key);
                Assert.AreEqual(SerializationMemberGroup.CatelProperty, properties[0].Value.MemberGroup);

                Assert.AreEqual("ExcludedCatelProperty", properties[1].Key);
                Assert.AreEqual(SerializationMemberGroup.CatelProperty, properties[1].Value.MemberGroup);

                Assert.AreEqual("ExcludedProtectedCatelProperty", properties[2].Key);
                Assert.AreEqual(SerializationMemberGroup.CatelProperty, properties[2].Value.MemberGroup);
            }
예제 #5
0
            public void ThrowsArgumentNullExceptionForNullType()
            {
                var serializationManager = new SerializationManager();

                ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => serializationManager.GetCatelProperties(null));
            }
예제 #6
0
        /// <summary>
        /// Populates the model with the specified members.
        /// </summary>
        /// <param name="context">The serialization context.</param>
        /// <param name="members">The members.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="context"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="members"/> is <c>null</c>.</exception>
        protected virtual void PopulateModel(ISerializationContext <TSerializationContextInfo> context, List <MemberValue> members)
        {
            Argument.IsNotNull("model", context);
            Argument.IsNotNull("members", members);

            if (members.Count > 0)
            {
                var firstMember = members[0];
                if (firstMember.MemberGroup == SerializationMemberGroup.SimpleRootObject)
                {
                    // Completely replace root object (this is a basic (non-reference) type)
                    context.Model = firstMember.Value;
                }
                else if (firstMember.MemberGroup == SerializationMemberGroup.Dictionary)
                {
                    var targetDictionary = context.Model as IDictionary;
                    if (targetDictionary is null)
                    {
                        throw Log.ErrorAndCreateException <NotSupportedException>("'{0}' seems to be a dictionary, but target model cannot be updated because it does not implement IDictionary",
                                                                                  context.ModelTypeName);
                    }

                    targetDictionary.Clear();

                    var sourceDictionary = firstMember.Value as IDictionary;
                    if (sourceDictionary != null)
                    {
                        foreach (var key in sourceDictionary.Keys)
                        {
                            targetDictionary.Add(key, sourceDictionary[key]);
                        }
                    }
                }
                else if (firstMember.MemberGroup == SerializationMemberGroup.Collection)
                {
                    if (context.ModelType.IsArrayEx())
                    {
                        context.Model = firstMember.Value;
                    }
                    else
                    {
                        var targetCollection = context.Model as IList;
                        if (targetCollection is null)
                        {
                            throw Log.ErrorAndCreateException <NotSupportedException>("'{0}' seems to be a collection, but target model cannot be updated because it does not implement IList",
                                                                                      context.ModelTypeName);
                        }

                        targetCollection.Clear();

                        var sourceCollection = firstMember.Value as IEnumerable;
                        if (sourceCollection != null)
                        {
                            foreach (var item in sourceCollection)
                            {
                                targetCollection.Add(item);
                            }
                        }
                    }
                }
                else
                {
                    // Populate using properties
                    var model     = context.Model;
                    var modelType = context.ModelType;

                    var modelInfo = _serializationModelCache.GetFromCacheOrFetch(modelType, () =>
                    {
                        var catelProperties   = SerializationManager.GetCatelProperties(modelType);
                        var fields            = SerializationManager.GetFields(modelType);
                        var regularProperties = SerializationManager.GetRegularProperties(modelType);

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

                    foreach (var member in members)
                    {
                        ObjectAdapter.SetMemberValue(model, member, modelInfo);
                    }
                }
            }
        }