Beispiel #1
0
        private static void AddMember(ServiceTypeFieldCollection result, MemberInfo member, Type memberType)
        {
            var attributes = member.GetCustomAttributes(typeof(ProtoMemberAttribute), true);

            if (attributes.Length == 0)
                return;

            Debug.Assert(attributes.Length == 1);

            var attribute = (ProtoMemberAttribute)attributes[0];

            result.Add(new ServiceTypeField(
                ReflectionOptimizer.BuildGetter(member),
                ReflectionOptimizer.BuildSetter(member, true),
                attribute.Tag,
                attribute.IsRequired,
                memberType
            ));
        }
Beispiel #2
0
        private static void AddMember(ServiceAssembly assembly, ServiceTypeFieldCollection result, MemberInfo member, Type memberType)
        {
            var attributes = member.GetCustomAttributes(typeof(ProtoMemberAttribute), true);

            if (attributes.Length == 0)
                return;

            Debug.Assert(attributes.Length == 1);

            var attribute = (ProtoMemberAttribute)attributes[0];

            var shouldSerializeMember = member.DeclaringType.GetMethod(
                "ShouldSerialize" + member.Name,
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
            );

            result.Add(new ServiceTypeField(
                assembly,
                ReflectionOptimizer.BuildGetter(member),
                ReflectionOptimizer.BuildSetter(member, true),
                shouldSerializeMember == null ? null : ReflectionOptimizer.BuildShouldSerializeInvoker(shouldSerializeMember),
                attribute.Tag,
                attribute.IsRequired,
                memberType
            ));
        }