示例#1
0
        private void ProcessMember(MemberInfo memberInfo, List <KeyValuePair <int, MemberFormatter> > formatters, ref int count)
        {
            var keys = memberInfo.GetCustomAttributes <KeyAttribute>();

            foreach (var key in keys)
            {
                if (key.Value == -1)
                {
                    if (LastKeyAttribute == null)
                    {
                        LastKeyAttribute = new LastKeyAttribute();
                        Logger.Instance.Error("Type {0} contains unsetted keys, but it has no one [LastKey] attribute. Saves won't work properly!", Type.FullName);
                    }
                    key.Value = LastKeyAttribute.Value++;
                }

                if (key.DistributedSubPath != null)
                {
                    var flags             = key.Flags | SerializationFlags.Distributed;
                    var externalFormatter = MemberFormatter.CreateDistributed(memberInfo, flags, key.DistributedSubPath);
                    formatters.Add(new KeyValuePair <int, MemberFormatter>(key.Value, externalFormatter));
                }
                var formatter = MemberFormatter.Create(memberInfo, key.Flags);
                formatters.Add(new KeyValuePair <int, MemberFormatter>(key.Value, formatter));
                count = Math.Max(count, key.Value + 1);
            }
        }
示例#2
0
        private void InitMemberFormatters()
        {
            var count      = 0;
            var formatters = new List <KeyValuePair <int, MemberFormatter> >();

            LastKeyAttribute = Type.GetCustomAttribute <LastKeyAttribute>(false);

            var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly;

            foreach (var fieldInfo in Type.GetFields(flags))
            {
                ProcessMember(fieldInfo, formatters, ref count);
            }
            foreach (var propertyInfo in Type.GetProperties(flags))
            {
                ProcessMember(propertyInfo, formatters, ref count);
            }

            MemberFormatterGroups = new MemberFormatterGroup[count];
            foreach (var pair in formatters)
            {
                var group = MemberFormatterGroups[pair.Key];
                if (group == null)
                {
                    group = new MemberFormatterGroup();
                    MemberFormatterGroups[pair.Key] = group;
                }
                group.Add(pair.Value);
            }
        }