Esempio n. 1
0
        static MemberEntry[] GetMemberEntries(Type type)
        {
            var members = GetMembers(type);
            var entries = new List <MemberEntry>();
            var nameSet = new HashSet <string>();

            foreach (var member in members)
            {
                var attrs = member.GetCustomAttributes(typeof(SaveGamePropertyAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                var entry = new MemberEntry(member);

                if (nameSet.Add(entry.Name) == false)
                {
                    throw new Exception("duplicate name");
                }

                entries.Add(entry);
            }

            // XXX don't sort. this makes objectid deserialized first, which "fixes" issues with KeyedCollection
            //entries.Sort(CompareEntries);

            return(entries.ToArray());
        }
Esempio n. 2
0
        static int CompareEntries(MemberEntry a, MemberEntry b)
        {
            bool simpleA = TypeIsSimple(a.MemberType);
            bool simpleB = TypeIsSimple(b.MemberType);

            if ((simpleA && simpleB) || (!simpleA && !simpleB))
            {
                return(string.Compare(a.Name, b.Name, StringComparison.Ordinal));
            }
            else if (simpleA)
            {
                return(-1);
            }
            else
            {
                return(1);
            }
        }
Esempio n. 3
0
        static MemberEntry[] GetMemberEntries(Type type)
        {
            var members = GetMembers(type);
            var entries = new List<MemberEntry>();
            var nameSet = new HashSet<string>();

            foreach (var member in members)
            {
                var attrs = member.GetCustomAttributes(typeof(SaveGamePropertyAttribute), false);
                if (attrs.Length == 0)
                    continue;

                var entry = new MemberEntry(member);

                if (nameSet.Add(entry.Name) == false)
                    throw new Exception("duplicate name");

                entries.Add(entry);
            }

            // XXX don't sort. this makes objectid deserialized first, which "fixes" issues with KeyedCollection
            //entries.Sort(CompareEntries);

            return entries.ToArray();
        }
Esempio n. 4
0
        static int CompareEntries(MemberEntry a, MemberEntry b)
        {
            bool simpleA = TypeIsSimple(a.MemberType);
            bool simpleB = TypeIsSimple(b.MemberType);

            if ((simpleA && simpleB) || (!simpleA && !simpleB))
                return string.Compare(a.Name, b.Name, StringComparison.Ordinal);
            else if (simpleA)
                return -1;
            else
                return 1;
        }