Пример #1
0
        public OptionalReadWriteMemberSerializationMediatorDecorator([NotNull] IMemberSerializationMediator <TContainingType> mediator, [NotNull] string memberName)
        {
            if (mediator == null)
            {
                throw new ArgumentNullException(nameof(mediator));
            }
            if (string.IsNullOrWhiteSpace(memberName))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(memberName));
            }

            //Get member and check no ambious matches
            MemberInfo[] info = typeof(TContainingType)
                                .GetTypeInfo()
                                .GetMember(memberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            if (info == null || info.Length == 0)
            {
                throw new InvalidOperationException($"Didn't find Member: {memberName} for Optional functionality on Type: {typeof(TContainingType).Name}. Make sure the member is implemented on the Type. Use nameof for compile time safety.");
            }
            if (info.Length > 1)
            {
                throw new InvalidOperationException($"Found ambigious Member: {memberName} for Optional functionality on Type: {typeof(TContainingType).Name}.");
            }

            isReadWriteEnabledGetter = new MemberGetterMediator <TContainingType>(info.First());

            DecoratedMediator = mediator;
        }
        /// <inheritdoc />
        public ConnectedCollectionCollectionSerializationMediator([NotNull] MemberInfo collectionMemberInfo, [NotNull] MemberInfo sizeMemberInfo, [NotNull] ITypeSerializerStrategy serializer, [NotNull] IMemberSerializationMediator <TContainingType> decoratedMediator)
            : base(collectionMemberInfo, serializer)
        {
            if (collectionMemberInfo == null)
            {
                throw new ArgumentNullException(nameof(collectionMemberInfo));
            }
            if (decoratedMediator == null)
            {
                throw new ArgumentNullException(nameof(decoratedMediator));
            }

            SizeMemberGetter  = new MemberGetterMediator <TContainingType>(sizeMemberInfo);
            DecoratedMediator = decoratedMediator;
        }
        protected MemberSerializationMediator([NotNull] MemberInfo memberInfo, [NotNull] ITypeSerializerStrategy serializer)
            : base(memberInfo, serializer)
        {
            if (memberInfo == null)
            {
                throw new ArgumentNullException(nameof(memberInfo));
            }
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            //Due to perf problems fasterflect setting wasn't fast enough.
            //Introducing a compiled lambda to delegate for get/set should provide the much needed preformance.
            MemberSetter = new MemberSetterMediator <TContainingType, TMemberType>(memberInfo);
            MemberGetter = new MemberGetterMediator <TContainingType>(memberInfo);
            //TODO: Handle for net35. Profile fasterflect vs reflection emit
        }