Example #1
0
        private static MemberMappingCollection CreateMemberMappings(Type objectType)
        {
            List <MemberInfo>       members        = ReflectionUtils.GetFieldsAndProperties(objectType, BindingFlags.Public | BindingFlags.Instance);
            MemberMappingCollection memberMappings = new MemberMappingCollection();

            foreach (MemberInfo member in members)
            {
                JsonPropertyAttribute propertyAttribute = ReflectionUtils.GetAttribute <JsonPropertyAttribute>(member, true);
                string mappedName = propertyAttribute != null ? propertyAttribute.PropertyName : member.Name;

                bool          ignored       = member.IsDefined(typeof(JsonIgnoreAttribute), true);
                bool          readable      = ReflectionUtils.CanReadMemberValue(member);
                bool          writable      = ReflectionUtils.CanSetMemberValue(member);
                MemberMapping memberMapping = new MemberMapping(mappedName, member, ignored, readable, writable);

                memberMappings.AddMapping(memberMapping);
            }

            return(memberMappings);
        }
Example #2
0
        private static MemberMappingCollection CreateMemberMappings(Type objectType)
        {
            List<MemberInfo> members = ReflectionUtils.GetFieldsAndProperties(objectType, BindingFlags.Public | BindingFlags.Instance);
              MemberMappingCollection memberMappings = new MemberMappingCollection();

              foreach (MemberInfo member in members)
              {
              JsonPropertyAttribute propertyAttribute = ReflectionUtils.GetAttribute<JsonPropertyAttribute>(member, true);
            string mappedName = propertyAttribute != null ? propertyAttribute.PropertyName : member.Name;

            bool ignored = member.IsDefined(typeof (JsonIgnoreAttribute), true);
            bool readable = ReflectionUtils.CanReadMemberValue(member);
            bool writable = ReflectionUtils.CanSetMemberValue(member);
            MemberMapping memberMapping = new MemberMapping(mappedName, member, ignored, readable, writable);

            memberMappings.AddMapping(memberMapping);
              }

              return memberMappings;
        }