コード例 #1
0
        /// <summary>
        /// Recurse the bindings for serialization.
        /// </summary>
        /// <param name="list">The list of <see cref="MemberBinding"/>.</param>
        /// <param name="state">The <see cref="SerializationState"/>.</param>
        /// <returns>The list of serialized bindings.</returns>
        private IEnumerable <object> SerializeBindings(IEnumerable <MemberBinding> list, SerializationState state)
        {
            var result = new List <object>();

            foreach (var binding in list)
            {
                switch (binding)
                {
                case MemberAssignment assignment:
                    var serializableBinding = new MemberBindingAssignment
                    {
                        Expression =
                            Serializer.Serialize(assignment.Expression, state),
                        MemberInfoKey = GetKeyForMember(assignment.Member),
                    };
                    result.Add(serializableBinding);
                    break;

                case MemberMemberBinding memberBinding:
                    var memberBindingSerializable = new MemberBindingMember
                    {
                        MemberKey = GetKeyForMember(memberBinding.Member),
                    };
                    memberBindingSerializable.Bindings.AddRange(
                        SerializeBindings(memberBinding.Bindings, state));
                    result.Add(memberBindingSerializable);
                    break;

                case MemberListBinding listBinding:
                    var memberListSerializable = new MemberBindingList
                    {
                        MemberKey =
                            GetKeyForMember(listBinding.Member),
                    };
                    foreach (var initializer in listBinding.Initializers)
                    {
                        var init = new MemberBindingInitializer
                        {
                            AddMethodKey = GetKeyForMember(initializer.AddMethod),
                        };
                        foreach (var argument in initializer.Arguments)
                        {
                            init.Arguments.Add(Serializer.Serialize(argument, state));
                        }

                        memberListSerializable.Initializers.Add(init);
                    }

                    result.Add(memberListSerializable);
                    break;
                }
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Deserializes an assignment.
        /// </summary>
        /// <param name="element">The <see cref="MemberBindingAssignment"/> to parse.</param>
        /// <param name="state">The <see cref="SerializationState"/>.</param>
        /// <returns>The <see cref="MemberAssignment"/>.</returns>
        private MemberBinding DeserializeAssignment(MemberBindingAssignment element, SerializationState state)
        {
            var key = element.MemberInfoKey;

            typesCompressor.Value.DecompressTypes(
                state.TypeIndex,
                (key, newKey => key = newKey));
            var member = GetMemberFromKey(key);

            AuthorizeMembers(member);

            var expression = Serializer.Deserialize(
                element.Expression,
                state);

            return(Expression.Bind(member, expression));
        }