Ejemplo n.º 1
0
        private static void FindSerializableMembers(Type type, List <MemberInfo> members, ISerializationPolicy policy)
        {
            const BindingFlags Flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly;

            if (type.BaseType != typeof(object) && type.BaseType != null)
            {
                FindSerializableMembers(type.BaseType, members, policy);
            }

            foreach (var member in type.GetMembers(Flags).Where(n => n is FieldInfo || n is PropertyInfo))
            {
                if (policy.ShouldSerializeMember(member))
                {
                    bool nameAlreadyExists = members.Any(n => n.Name == member.Name);

                    if (MemberIsPrivate(member) && nameAlreadyExists)
                    {
                        members.Add(GetPrivateMemberAlias(member));
                    }
                    else if (nameAlreadyExists)
                    {
                        members.Add(GetPrivateMemberAlias(member));
                    }
                    else
                    {
                        members.Add(member);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static void FindSerializableMembers(Type type, List <MemberInfo> members, ISerializationPolicy policy)
        {
            const BindingFlags Flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly;

            if (type.BaseType != typeof(object) && type.BaseType != null)
            {
                FindSerializableMembers(type.BaseType, members, policy);
            }

            foreach (var member in type.GetMembers(Flags).Where(n => n is FieldInfo || n is PropertyInfo))
            {
                if (policy.ShouldSerializeMember(member))
                {
                    bool nameAlreadyExists = members.Any(n => n.Name == member.Name);

                    if (MemberIsPrivate(member) && nameAlreadyExists)
                    {
                        members.Add(GetPrivateMemberAlias(member));
                    }
                    else if (nameAlreadyExists)
                    {
                        members.Add(GetPrivateMemberAlias(member));
                    }
                    else
                    {
                        members.Add(member);
                    }
                }
            }
            // ensure non-auto properties come last as their getters/setters may depend on other members
            members.Sort((a, b) => (a.IsNonAutoProperty()).CompareTo(b.IsNonAutoProperty()));
        }