コード例 #1
0
        private static ArgumentUnpacker GetTupleArgumentUnpacker(MethodInfo method)
        {
            Type tupleType = TaskExtensions.UnwrapReturnType(method.ReturnType);

            IEnumerable <string> transformNames = null;

            if (method.ReturnParameter.IsDefined(typeof(TupleElementNamesAttribute)))
            {
                TupleElementNamesAttribute attribute =
                    method.ReturnParameter.GetCustomAttribute <TupleElementNamesAttribute>();

                transformNames = attribute.TransformNames;
            }

            return(ArgumentUnpackerHelper.GetValueTupleArgumentUnpacker
                       (tupleType, transformNames));
        }
コード例 #2
0
        protected WampEventValueTupleConverter()
        {
            Type tupleType = typeof(TTuple);

            if (!tupleType.IsValueTuple())
            {
                throw new ArgumentException("Expected TTuple to be a ValueTuple");
            }

            if (!tupleType.IsValidTupleType())
            {
                throw new ArgumentException("TTuple is an invalid ValueTuple. Expected TRest to be a ValueTuple.");
            }

            mArrayConverter = ValueTupleArrayConverter <TTuple> .Value;

            Type converterType = GetConverterType();

            ValidateConverterType(converterType);

            IList <string> transformNames = GetTransformNames(converterType);

            int tupleLength = tupleType.GetValueTupleLength();

            ValidateTransformNames(transformNames, tupleLength);

            if (transformNames != null)
            {
                if (transformNames.Take(tupleLength).All(x => x != null))
                {
                    mDictionaryConverter =
                        ValueTupleDictionaryConverterBuilder.Build(tupleType, transformNames);
                }
            }

            mArgumentUnpacker =
                ArgumentUnpackerHelper.GetValueTupleArgumentUnpacker
                    (tupleType, transformNames);
        }