private MemberSetter CreateMemberSetter(SerializingMember member)
        {
            var fieldInfo = member.Member as FieldInfo;

            if (fieldInfo != null)
            {
                return(delegate(ref object target, object memberValue)
                {
                    fieldInfo.SetValue(target, memberValue);
                });
            }
            else
            {
                var propertyInfo = member.Member as PropertyInfo;
                Contract.Assert(propertyInfo != null, member.ToString() + ":" + member.GetType());
                var propertySetter = propertyInfo.GetSetMethod();

                return(delegate(ref object target, object memberValue)
                {
                    propertySetter.Invoke(target, new object[] { memberValue });
                });
            }


            // Expression.Lambda<MemberSetter>(
            //    Expression.Assign(
            //        Expression.PropertyOrField(
            //            refTargetParameter,
            //            m.Member.Name
            //        ),
            //        Expression.Call(
            //            Metadata._UnpackHelpers.ConvertWithEnsuringNotNull_1Method.MakeGenericMethod(m.Member.GetMemberValueType()),
            //            valueParameter,
            //            Expression.Constant(m.Member.Name),
            //            Expression.Call( // Using RuntimeTypeHandle to avoid WinRT expression tree issue.
            //                null,
            //                Metadata._Type.GetTypeFromHandle,
            //                Expression.Constant(m.Member.DeclaringType.TypeHandle)
            //            )
            //        )
            //    ),
            //    refTargetParameter,
            //    valueParameter
            //).Compile()
        }
        private static Func <object, object> CreateMemberGetter(SerializingMember member)
        {
            Func <object, object> coreGetter;

            var fieldInfo = member.Member as FieldInfo;

            if (fieldInfo != null)
            {
                coreGetter = target => fieldInfo.GetValue(target);
            }
            else
            {
                var propertyInfo = member.Member as PropertyInfo;
                Contract.Assert(propertyInfo != null, member.ToString() + ":" + member.GetType());
                var propertyGetterInfo = propertyInfo.GetGetMethod();
                coreGetter = target => propertyGetterInfo.Invoke(target, new object[0]);
            }

            if (member.Contract.NilImplication == NilImplication.Prohibit)
            {
                var name = member.Contract.Name;
                return(target =>
                {
                    var gotten = coreGetter(target);
                    if (gotten == null)
                    {
                        throw SerializationExceptions.NewNullIsProhibited(name);
                    }

                    return gotten;
                });
            }
            else
            {
                return(coreGetter);
            }
        }
        private MemberSetter CreateMemberSetter(SerializingMember member)
        {
            var fieldInfo = member.Member as FieldInfo;

            if (fieldInfo != null)
            {
                return delegate(ref object target, object memberValue)
                {
                    fieldInfo.SetValue(target, memberValue);
                };
            }
            else
            {
                var propertyInfo = member.Member as PropertyInfo;
                Contract.Assert(propertyInfo != null, member.ToString() + ":" + member.GetType());
                var propertySetter = propertyInfo.GetSetMethod();

                return delegate(ref object target, object memberValue)
                {
                    propertySetter.Invoke(target, new object[] { memberValue });
                };
            }


            // Expression.Lambda<MemberSetter>(
            //    Expression.Assign(
            //        Expression.PropertyOrField(
            //            refTargetParameter,
            //            m.Member.Name
            //        ),
            //        Expression.Call(
            //            Metadata._UnpackHelpers.ConvertWithEnsuringNotNull_1Method.MakeGenericMethod(m.Member.GetMemberValueType()),
            //            valueParameter,
            //            Expression.Constant(m.Member.Name),
            //            Expression.Call( // Using RuntimeTypeHandle to avoid WinRT expression tree issue.
            //                null,
            //                Metadata._Type.GetTypeFromHandle,
            //                Expression.Constant(m.Member.DeclaringType.TypeHandle)
            //            )
            //        )
            //    ),
            //    refTargetParameter,
            //    valueParameter
            //).Compile()
        }
        private static Func<object, object> CreateMemberGetter(SerializingMember member)
        {
            Func<object, object> coreGetter;

            var fieldInfo = member.Member as FieldInfo; 

            if (fieldInfo != null)
            {
                coreGetter = target => fieldInfo.GetValue(target);
            }
            else
            {
                var propertyInfo = member.Member as PropertyInfo;
                Contract.Assert(propertyInfo != null, member.ToString() + ":" + member.GetType());
                var propertyGetterInfo = propertyInfo.GetGetMethod();
                coreGetter = target => propertyGetterInfo.Invoke(target, new object[0]);
            }

            if (member.Contract.NilImplication == NilImplication.Prohibit)
            {
                var name = member.Contract.Name;
                return target =>
                {
                    var gotten = coreGetter(target);
                    if (gotten == null)
                    {
                        throw SerializationExceptions.NewNullIsProhibited(name);
                    }

                    return gotten;
                };
            }
            else
            {
                return coreGetter;
            }
        }